Simon Shi

放飞梦想,专注于Mobile开发

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: 订阅 订阅 :: 管理 ::

For iOS 5:

You should use shouldAutorotateToInterfaceOrientation: method of UIViewController, but it’s depredated in iOS6.

For iOS 6;

You should set interface orientations in project's summary setting or Info.plist. If necessary, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.


But if you want to support both Xcode 4.4 iOS 5.1 and Xcode 4.5 iOS 6.0, sample code below(we want to make our project support only landscape left and right):

#pragma mark - support orientation for both iOS5 and iOS6

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
//use for iOS6
- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate{
    return YES;
}
#endif

//use for iOS5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

 

posted on 2012-09-25 16:39  Simon Shi  阅读(320)  评论(0编辑  收藏  举报