我想以编程方式更改 UITableview
的位置。我在 viewDidLoad
,ViewWillAppear
回调中添加了以下代码,但位置没有改变。
Table.frame = CGRectMake(0,100,320,200);
当我在 Storyboard 中禁用 Auto Layout
选项时,Table View 的位置会发生变化。但是,我需要保留 Auto Layout
选项以保持对不同设备类型的支持。
最佳答案
使用自动布局,并对 tableView 的位置和大小设置约束。
然后,创建 NSLayoutConstraint
类型的 IBOutlet
实例,并将它们附加到 xib 中的约束。
然后,在您的代码中,设置约束值以重置 TableView 位置。
示例代码:
在你的 .h 文件中:
@property IBOutlet NSLayoutConstraint *tableOriginX;
@property IBOutlet NSLayoutConstraint *tableOriginY;
@property IBOutlet NSLayoutConstraint *tableWidth;
@property IBOutlet NSLayoutConstraint *tableHeight;
然后,在您要更改表格框架的 .m 文件中:
tableOriginX.constant = 0;
tableOriginY.constant = 100;
tableWidth.constant = 320;
tableHeight.constant = 200;
关于ios - 使用自动布局支持以编程方式更改 UITableView 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24305728/