对于一个 iPad 项目,我实现了一个类似 NSBrowser 的界面,它支持动态数量的列。每列由一个 UITableView 表示。
添加或删除列时,我使用 UIView 的 animateWithDuration:animations: 来更改 UITableView 的宽度。
我遇到的问题:
系统为每个表格 View 单元格的 imageView 添加了不需要的帧大小动画,该动画将 imageView 从非常大调整为初始大小。这看起来真的很尴尬,所以我正在寻找摆脱它的方法 - 同时保持封闭 tableViews 的动画帧大小变化。
有什么想法我可能做错了吗?
我在这里发布了一个示例项目演示该问题:
https://github.com/iljaiwas/TableViewFrameTest
这是我设置单元格的地方:
https://github.com/iljaiwas/TableViewFrameTest/blob/master/TableViewFrameTest/TestTableViewController.m#L61
这是我触发动画的地方:
https://github.com/iljaiwas/TableViewFrameTest/blob/master/TableViewFrameTest/TestViewController.m#L46
最佳答案
我遇到了同样的问题,并找到了这个链接(http://www.objc.io/issue-5/iOS7-hidden-gems-and-workarounds.html),其中有一个关于阻止动画的部分。
要使您的示例正常工作,请在导入语句之后的 TestTableViewController.m 顶部添加以下内容:
@interface MyTableViewCell : UITableViewCell
@end
@implementation MyTableViewCell
- (void) layoutSubviews {
[UIView performWithoutAnimation:^{
[super layoutSubviews];
}];}
@end
然后将 viewDidLoad 中的以下行更改为使用 MyTableViewCell:
[self.tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"Cell"];
现在运行该示例,您将不再拥有不需要的图像动画。
关于ios - 调整 UITableView 大小时不需要的图像动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19711958/