Kunal Balani
Kunal Balani

Reputation: 4789

UIwindow returns me a frame with incorrect height and width

I am running a test program with a sample view controller . In my app delegate , I have the following

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSLog(@"window frame %@",NSStringFromCGRect(self.window.frame));
}

The output is window frame {{0, 0}, {768, 1024}}. I have the device in lanscape mode but the window frame returns a swapped value of width and height .

I am not able to place my view components using hard coded values because of this . Any clues what is going wrong.

Upvotes: 0

Views: 1318

Answers (1)

Kibitz503
Kibitz503

Reputation: 867

You are trying to get the size of the view before this function is called...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

This only gets called after

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

exits. Is there a reason you need to do it inside of this function? I would try doing it inside of your UIViewControllers viewDidLoad function instead.

Hope this helps :)

Upvotes: 2

Related Questions