A view controller is in landscape mode, but I'm getting the frame from portrait mode?

后端 未结 3 1115
有刺的猬
有刺的猬 2021-02-10 19:47

I have a settings view controller with a table view. The table view is supposed to set its frame to be the frame of the view controller. My app only supports landscape mode, so

相关标签:
3条回答
  • 2021-02-10 20:00

    when you call [UIView init] it will default to the screen size of your device in portrait mode (same goes for iPad but with larger size). Inside [UIViewController viewDidLoad] the self.view will also default to this size.

    Screen rotation is only done to the top view (controller) in your hierarchy and rotation messages are forwarded through container-VCs that support this behavior (e.g. UINavigationController, UITabBarController).

    If you want your view to be sized correctly, use [UIView initWithFrame:self.view.bounds] for creating a view. Insinde UIViewController you only have the chance to override the loadView Method to set the frame before viewDidLoad gets called (or you could use a different XIB for landscape). You could also hardcode the view's size by setting its frame first thing in viewDidLoad

    0 讨论(0)
  • 2021-02-10 20:05

    You can use viewWillAppear to size your views before they display

    0 讨论(0)
  • 2021-02-10 20:17

    You have to implement this in your settings view controller:-

    -(void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
        }
    
    0 讨论(0)
提交回复
热议问题