Reputation: 61850
This is what I do when cell is gonna be displayed:
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if let reorderControl = cell.huntedSubviewWithClassName("UITableViewCellReorderControl") {
let resizedReorderControl = UIView(frame: CGRectMake(0, 0, CGRectGetMaxX(reorderControl.frame), CGRectGetMaxY(reorderControl.frame)))
resizedReorderControl.addSubview(reorderControl)
cell.addSubview(resizedReorderControl)
let sizeDifference = CGSizeMake(resizedReorderControl.frame.size.width - reorderControl.frame.size.width, resizedReorderControl.frame.size.height - reorderControl.frame.size.height)
let transformRatio = CGSizeMake(resizedReorderControl.frame.size.width / reorderControl.frame.size.width, resizedReorderControl.frame.size.height / reorderControl.frame.size.height)
var transform = CGAffineTransformIdentity
transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height)
transform = CGAffineTransformTranslate(transform, -sizeDifference.width / 2, -sizeDifference.height / 2)
resizedReorderControl.transform = transform
}
}
Simple get reorder view and transform this to make it able reorder cell tapping on a whole cell. But there was left a space after moving reorder control to different subview.
The cell just displayed:
The cell while moving:
The cell should look like this (be able to reorder without space for reorder control):
What do I mean?
My idea was to reorder the UITableViewCell
by tapping any place on it (not only by tapping triple lines on the right side). Then I get these UIView
and spread this all over the cell. But some problem arised. The space of triple lines left empty. What to do to remove that space?
Upvotes: 2
Views: 1036
Reputation: 51
I would not recommend accessing a private class (UITableViewCellReorderControl) as Apple discourages it. On top of that, they have all the right to make any modifications around this property whenever they need. But if you still need to remove the empty space on the right after adding the above code you have posted already, just add this code to your UITableViewCell subclass:
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame.size.width = frame.size.width
}
Its just a workaround by the way.
Upvotes: 2