Automatically Sizing UIView after Adding to Window

前端 未结 6 908
孤街浪徒
孤街浪徒 2020-12-16 06:41

Note: This may be a duplicate of Subview Doesnt AutoSize When Added to Root View Controller


I have an iPad app that switches between different views in its mai

6条回答
  •  庸人自扰
    2020-12-16 06:59

    The window may include other UI elements besides your view. The 20 pixel difference in your example is the height of the status bar.

    [[UIApplication sharedApplication] statusBarFrame].height;
    

    Neither the window nor screen rotate. Getting their frames and using them for a rotated view will only work if you have switched the height and width.

    If you are using a UIViewController, try returning YES from this method:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; // Override to allow rotation. Default returns YES only for UIDeviceOrientationPortrait
    

提交回复
热议问题