From the perspective of IOS code snippets, the technology is quite convenient and reprinted here.
In xcode4, you can easily configure the IOS Project to Support Device orientation in the project property settings,
Unfortunately, this setting only stores related settings in plist. If you really want to control the device flip support for a uiview, You have to toss in the related uiviewcontroller-shouldautorotatetointerfaceorientation: function, yes or no is returned Based on the device direction.
This code snippet simplifies related operations. With this code, you can directly query plist settings in the shouldautorotatetointerfaceorientation function, and return results based on the settings, instead of making one-to-one judgments using manual code.
static inline NSString * NSStringFromUIInterfaceOriention(UIInterfaceOrientation orientation){ switch (orientation) { case UIInterfaceOrientationPortrait: return @"UIInterfaceOrientationPortrait"; case UIInterfaceOrientationPortraitUpsideDown: return @"UIInterfaceOrientationPortraitUpsideDown"; case UIInterfaceOrientationLandscapeLeft: return @"UIInterfaceOrientationLandscapeLeft"; case UIInterfaceOrientationLandscapeRight: return @"UIInterfaceOrientationLandscapeRight"; default: return @"Unexpected"; }}static inline BOOL UIInterfaceOrientationIsSupportedOrientation(UIInterfaceOrientation interfaceOrientation){ NSArray *array = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"]; NSUInteger index = [array indexOfObject:NSStringFromUIInterfaceOriention(interfaceOrientation)]; return index != NSNotFound;}
Use shouldautorotatetointerfaceorientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return UIInterfaceOrientationIsSupportedOrientation(interfaceOrientation);}
And: some people hate global functions. You can also consider blocking them into uiviewcontroller as a category. Adding self to the call is quite elegant.