ios6,ios7强制转屏

在父视图控制器里面写以下代码spa

-(void)setViewOrientation:(UIInterfaceOrientation )orientation
{
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        [[UIDevice currentDevice] performSelector:@selector(setOrientation:)
                                       withObject:(id)orientation];
    }
    [UIViewController attemptRotationToDeviceOrientation];//这句是关键
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

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

在子视图控制器的加入,这里子视图控制器要横屏code

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear :YES];
    [self setViewOrientation:UIInterfaceOrientationLandscapeRight];
}
//重写下面子类的方法

- (NSUInteger) supportedInterfaceOrientations{orm

    returnUIInterfaceOrientationMaskLandscapeRight;blog

}it

 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation NS_DEPRECATED_IOS(2_0, 6_0){io

    return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;form

}class

相关文章
相关标签/搜索