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

相關文章
相關標籤/搜索