iOS,UIScrollView 中的第一页启用横向,第二页禁用横向

iOS, first page in the UIScrollView enable landscape orientation and the second page disable the landscape orientation

有一个 UIScrollView,它有两个页面,在 UIScrollView 的第一页我想启用横向,在 UIScrollView 的第二页我想禁用横向,现在我使用下面的代码,但是还没有完善,第二页先横屏再竖屏:

- (void)viewWillAppear:(BOOL)animated {
    [ITNotificationCenter addObserver:self selector:@selector(handleDeviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)handleDeviceOrientationDidChange{
    if(isFirstPage){
        //landscape code
    } else {
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
}

我怎样才能做到这一点?每一个答案将不胜感激。

问题已解决。请看下面的代码。

AppDelegate.h 文件:

@property (nonatomaic, assign, getter=isNeedRotation) BOOL needRotation;

AppDelegate.m 文件:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (self.isNeedRotation) {
        return UIInterfaceOrientationMaskPortrait;
    }
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

yourUIViewController.m 文件:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.mainScrollView) {
        AppDelegate *appDelegate = (AppDelegate *)ITUIApplicationDelegate;
        if (scrollView.contentOffset.x < screen_width) {
            appDelegate.needRotation = YES;
        } else {
            appDelegate.needRotation = NO;
        }
    }
}