ios - 将重新排序符号放在 UITableViewCell 的左侧

标签 ios uitableview

我希望重新排序图(三行)显示在 UITableViewCell 的左侧,因为右侧将被覆盖的 UIView 隐藏。

我找到的这段代码:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    for(UIView* view in cell.subviews)
    {
        if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
        {
            // Creates a new subview the size of the entire cell
            UIView *movedReorderControl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
            // Adds the reorder control view to our new subview
            [movedReorderControl addSubview:view];
            // Adds our new subview to the cell
            [cell addSubview:movedReorderControl];
            // CGStuff to move it to the left
            CGSize moveLeft = CGSizeMake(movedReorderControl.frame.size.width - view.frame.size.width, movedReorderControl.frame.size.height - view.frame.size.height);
            CGAffineTransform transform = CGAffineTransformIdentity;
            transform = CGAffineTransformTranslate(transform, -moveLeft.width, -moveLeft.height);
            // Performs the transform
            [movedReorderControl setTransform:transform];
        }
    }
}

第一次加载表时工作正常。 但是,当单元格“重绘”时(例如前后滚动时),重新排序符号就会消失。

出了什么问题?

最佳答案

您不断移动重新排序控件相对于其当前位置的位置

CGSize moveLeft = CGSizeMake(movedReorderControl.frame.size.width - view.frame.size.width, movedReorderControl.frame.size.height - view.frame.size.height);

所以看起来像是将其移出了屏幕。尝试存储初始帧,然后使用它来移动 subview :

CGSize moveLeft = CGSizeMake(initialFrame.width - view.frame.size.width, initialFrame.width.height - view.frame.size.height);

关于ios - 将重新排序符号放在 UITableViewCell 的左侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15260976/

相关文章:

ios - 在 Xcode11 中用 Objective-C 将 UITableView 分成几个部分

ios - 当我启动 iPhone Retina 64 位模拟器时出现奇怪的应用程序行为

ios - 有什么可行的方法可以使用 UIWebView/WKWebView 在 UITableViewCell 中加载动态内容?

ios - 自动调整单元格大小在首次加载时不更新高度

ios - 使用 UI 测试或单元测试框架对库进行集成测试?

iphone - iOS 6 : UITableView Edit and Autoresizing

ios - 什么时候更新 UITableView 高度 NSLayoutConstraint 最合适

ios - SDWebImageCache 预缓存图像

ios - viewController 的 viewdidload 在 appDelegate 的方法之前调用

ios - ios中RTP协议(protocol)的使用方法