iOS開發筆記之代碼控制屏幕旋轉

// 能否自動旋轉

-(BOOL)shouldAutorotate{

    return NO;

}


// 支持的屏幕方向

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;

}


// 默認的屏幕方向

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{

    return UIInterfaceOrientationPortrait;

}


// 強制屏幕旋轉

- (void)setLandscape:(UIDeviceOrientation)orientation {

    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {

        SEL selector  = NSSelectorFromString(@"setOrientation:");

        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];

        [invocation setSelector:selector];

        [invocation setTarget:[UIDevice currentDevice]];

        [invocation setArgument:&orientation atIndex:2];

        [invocation invoke];

    }

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章