简体   繁体   English

Xcode 6中的大小类出现问题

[英]Trouble with size classes in Xcode 6

I'm meeting a very strange problem with size classes: 我在使用大小类遇到一个非常奇怪的问题:

  • In the size class any x any, I have a UITableViewController that contains a UIView with constraint width 150 and constraint height 150. 在任何x的大小类中,我都有一个UITableViewController ,其中包含一个约束宽度为150且约束高度为150的UIView

  • In the size class Regular x Regular, I "uninstall" these constraint, and I added another constraint width & height, with the size 250. 在尺寸类Regular x Regular中,我“卸载”了这些约束,并添加了另一个约束宽度和高度,大小为250。

When I launch my app on iPad, I can see the "correct" size of this UIView , but in my code, in ViewDidLoad , and ViewWillAppear , the size of this view is still "150". 当我在iPad上启动我的应用程序时,我可以看到此UIView的“正确”大小,但是在我的代码中,在ViewDidLoadViewWillAppear ,此视图的大小仍为“ 150”。 (I want to get the size of my view for few things.) Only in the function ViewDidAppear I've the correct size, but I don't understand why. (我想获得一些视图的大小。)仅在ViewDidAppear函数中,我具有正确的大小,但我不明白为什么。

Any ideas? 有任何想法吗?

Example code: 示例代码:

- (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);
}

viewDidLoad and viewWillAppear are not correct places to look for specific frame dimensions. viewDidLoadviewWillAppear不是寻找特定框架尺寸的正确位置。 Frame will be set after auto-layout is complete. 自动布局完成后将设置帧。

You can override viewDidLayoutSubviews and get it there. 您可以覆盖viewDidLayoutSubviews并将其到达那里。

So I think you have a bit of confusion regarding the size classes. 所以我认为您对尺寸等级有些困惑。 It's the same bit of confusion I had. 我有点困惑。

When you choose to view the size class as RegularxRegular, you're just viewing what it will look like in that mode. 当您选择将大小类查看为Re​​gularxRegular时,您只是在查看该模式下的样子。 Any changes you make there don't override the anyxany mode. 您在此处所做的任何更改都不会覆盖anyxany模式。

And you should probably not constrain a width and a height on your view. 而且您可能不应在视图上限制宽度和高度。 Try using constraints in relation to other views to get your UIView to look like it should on the screen. 尝试使用与其他视图相关的约束来使UIView看起来像在屏幕上一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM