Reputation: 1171
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);
}
Upvotes: 1
Views: 405
Reputation: 17860
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.
Upvotes: 2
Reputation: 3076
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.
Upvotes: 0