简体   繁体   中英

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.

  • In the size class Regular x Regular, I "uninstall" these constraint, and I added another constraint width & height, with the size 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". (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.

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. Frame will be set after auto-layout is complete.

You can override viewDidLayoutSubviews and get it there.

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. Any changes you make there don't override the anyxany mode.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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