简体   繁体   中英

shouldAutorotateToInterfaceOrientation return YES

I often see code like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

If the supported orientation is set in the project configuration, wouldn't just returning YES all the time be pointless? Or are there certain cases where this has an effect?

shouldAutorotateToInterfaceOrientation: (which is deprecated since iOS 6, by the way) is something completely different than the UISupportedInterfaceOrientations in the info plist! If you don't implement this method, the respective view controller won't ever autorotate to that interface orientation, no matter what you specify in UISupportedInterfaceOrientations .

From the documentation of UISupportedInterfaceOrientations :

The system uses this information (along with the current device orientation) to choose the initial orientation in which to launch your app .

Maybe in many parts of your application you support multiple interface orientations, but in one part you only support some of them (for example you want a video only to play in landscape)

So even if your app supports portrait, you probably want that the viewcontroller makes the orientation landscape

Edit: i'm commenting here because I can't comment other answers.

@daniel-rinser in iOS6, the system checks for project supported interface orientations, and intersects with viewcontroller's supported orientations, so it isn't only for launch but for all app execution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM