Reporting incorrect bounds in landscape Mode

前端 未结 9 1127
青春惊慌失措
青春惊慌失措 2020-12-05 02:57

I am having an issue with Landscape mode in my iPad application.

I created a very small new project to show my issue I set UIInterfaceOrientation in the pList to UII

9条回答
  •  感情败类
    2020-12-05 03:23

    Apart from viewDidAppear: make sure using _window.rootViewController instead of [_window addSubview:_rootViewController.view]. That also solved my issues on iOS6.

    AppDelegate.m:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
      _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
      _rootViewController = [[MyRootViewController alloc] init];
      _window.rootViewController = _rootViewController;
      [_window makeKeyAndVisible];
      return YES;
    }
    

    MyRootViewController.m:

    - (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      NSLog(@"bounds: %@", NSStringFromCGRect(self.view.bounds));
      UIView *myView = [[UIView alloc] initWithFrame:self.view.bounds];
      [self.view addSubview:myView];
    }
    

提交回复
热议问题