【发布时间】:2014-12-09 21:40:23
【问题描述】:
我遇到了一个关于尺寸等级的非常奇怪的问题:
在大小类 any x any 中,我有一个
UITableViewController,其中包含一个约束宽度为 150 和约束高度为 150 的UIView。在大小类Regular x Regular中,我“卸载”了这些约束,并添加了另一个约束宽度和高度,大小为250。
当我在 iPad 上启动我的应用程序时,我可以看到这个 UIView 的“正确”大小,但在我的代码中,在 ViewDidLoad 和 ViewWillAppear 中,这个视图的大小仍然是“150” . (我想为几件事获取视图的大小。)仅在函数ViewDidAppear 中,我的大小是正确的,但我不明白为什么。
有什么想法吗?
示例代码:
- (void)viewDidLoad {
[super viewDidLoad];
[self loadImg];
[self loadText];
self.navigationItem.hidesBackButton = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) loadText {
//
}
- (void) loadImg {
self.myView.layer.cornerRadius = self.myView.frame.size.width / 2;
self.myView.clipsToBounds = YES;
UIView *svg = [Utils defineImg:self.myView :@"myImage" :50];
[self.myView addSubview: svg];
svg.center = CGPointMake(self.myView.frame.size.width / 2, self.myView.frame.size.height / 2);
}
【问题讨论】:
-
我遇到了同样的问题,在 setNeedsDisplay 方法中使用自定义 UIImageView,我正在更改cornerRadius,但为此我需要框架的宽度。而且我的尺寸不对。我在 Interface Builder 中使用 Size Classes,顺便说一句
-
你可以看到我关于它的最后一个主题,有一个“解决方案”(真的不是最好的,但它有效。)
标签: ios objective-c xcode size-classes