How to get width of the main UIView in landscape mode?

ios, landscape, uiview, uiviewcontroller

Solution

Do the same in `viewWillAppear`.

-(void)viewWillAppear:(BOOL)animated{
    CGFloat mainViewWidth = self.view.bounds.size.width;
    NSLog(@"%f", mainViewWidth);
}

and see if you are getting correct values.. `ViewDidLoad` gets called before view is drawn completely. Accessing `UIView` size property gives you unpredictable values there.

Problem

When I use this code: ``` - (void)viewDidLoad { [super viewDidLoad]; CGFloat mainViewWidth = self.view.bounds.size.width; NSLog(@"%f", mainViewWidth); } ``` I got the result in simulator:480 and when i start the app on my iPhone 4 i got the result 320? Did I do something wrong?

Original source