Forcing landscape and autorotate in iOS 7

不打扰是莪最后的温柔 提交于 2019-11-30 18:20:41
ultra

This solves my problem. I'm not sure why I had issues before, but I must have missed trying this exact combination (also, info.plist should have the supported orientations set).

(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

(BOOL)shouldAutorotate {
    return YES;
}

edit: I may have having issues with the simulator, and doing a reset/restart and clean might have contributed to the fix.

Include this method as well in your code:

- (BOOL)shouldAutorotate{
  if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft ||[[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight)
  {
    return YES;
  }
  else{
    return NO;
  }
}

Read this for more info. Here it is mentioned that we should override shouldAutorotate to suppress orientations.

If you want to temporarily disable automatic rotation, avoid manipulating the orientation masks to do this. Instead, override the shouldAutorotate method on the topmost view controller. This method is called before performing any autorotation. If it returns NO, then the rotation is suppressed.

i don't know why, but this work for me on IOS 7

[[UIApplication sharedApplication] setStatusBarHidden:NO];

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

[super willRotateToInterfaceOrientation:UIInterfaceOrientationPortrait duration:0];

I may have having issues with the simulator, and doing a reset/restart and clean might have contributed to the fix.

This worked for me: (Simulator -> Reset Content and Settings...)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!