UITableViewCell subclass layout messed up in autoLayout-disabled Storyboard(UITableViewCell 子类布局在禁用自动布局的故事板中搞砸了)
问题描述
我在 Storyboard 中创建了一个表格视图,其中包含 Xcode 5 中未选中使用自动布局"的原型单元格.
I have created a table view with prototype cells in a Storyboard with the "Use Autolayout" unchecked in Xcode 5.
单元格是UITableViewCell的子类,主要是添加IBOutlets,里面没有代码.结果是混乱的布局.我尝试更改 Autoresizing 蒙版,但没有成功.也试过这个.
The cells are UITableViewCell subclasses, mainly to add IBOutlets and no code inside. The result is a messed layout. I tried changing the Autoresizing masks with no luck. Also tried this.
但是,如果我实现一个空的 layoutSubviews 则显示正常.知道发生了什么吗?自动布局仍然启用尽管取消选中它?
If I however implement an empty layoutSubviews it shows ok. Any idea of what's going on?
Is auto layout still enabled despite unchecking it?
更多细节...
@interface SettingDefaultTableViewCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *label;
@property (nonatomic, weak) IBOutlet UIImageView *imageView;
@property (nonatomic, weak) IBOutlet UIView *backgroundView;
@end
@implementation SettingDefaultTableViewCell
- (void)layoutSubviews
{
// Emtpy implementation to fix weird layout bug
}
@end
禁用自动布局的故事板:
Storyboard with Autolayout disabled:
未使用上述 layoutSubviews 修复时的结果:
Result when layoutSubviews fix above is not used:
编辑 2:
- 单元格设置为不自动调整子视图大小.
- 虽然以上内容应该足以防止子视图自动调整,但所有自动调整大小的蒙版都设置为仅灵活的右边距和下边距.
- 只有 > 标记设置为灵活的左边距.没有灵活的宽度或高度.
推荐答案
单元格被未记录的 UITableViewCell 的 layoutSubviews 修改:
The cell is getting modified by the undocumented UITableViewCell's layoutSubviews:
- 尽管没有设置自动调整大小的子视图,但默认实现会更改
backgroundView框架. - 尽管被配置为自定义样式单元格,它也会将
imageView(>")向左移动.
- Despite set not no autoresize subviews, the default implementation changes the
backgroundViewframe. - It also moves
imageView(the ">") to the left despite being configured as a Custom Style cell.
从而避免执行 super 的 layoutSubviews 修复它.
Thus avoiding executing super's layoutSubviews fixes it.
这篇关于UITableViewCell 子类布局在禁用自动布局的故事板中搞砸了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableViewCell 子类布局在禁用自动布局的故事板中搞砸了
基础教程推荐
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
