ios6,ios7強制轉屏


在父視圖控制器里面寫如下代碼

-(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;
}

在子視圖控制器的加入,這里子視圖控制器要橫屏

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

- (NSUInteger) supportedInterfaceOrientations{

    returnUIInterfaceOrientationMaskLandscapeRight;

}

 

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

    return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;

}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM