iOS 強(qiáng)制轉(zhuǎn)屏 強(qiáng)制橫屏 強(qiáng)制豎屏

今天項(xiàng)目中遇到正在看視頻的時(shí)候賬號被擠,如果當(dāng)時(shí)是橫屏的情況下,需要強(qiáng)制豎屏。真頭疼,網(wǎng)上找了好多方法,終于解決啦。O(∩_∩)O~

強(qiáng)制橫屏:

[self interfaceOrientation:UIInterfaceOrientationLandscapeRight];

強(qiáng)制豎屏:

[self interfaceOrientation:UIInterfaceOrientationPortrait];

強(qiáng)制轉(zhuǎn)屏

- (void)interfaceOrientation:(UIInterfaceOrientation)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]];
        int val = orientation;
        // 從2開始是因?yàn)? 1 兩個(gè)參數(shù)已經(jīng)被selector和target占用
        [invocation setArgument:&val atIndex:2];
        [invocation invoke];
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容