iOS控制視頻的橫豎屏

1:首先大家有點(diǎn)懵,其實(shí)好好研究下就可以

  • 控制橫豎屏Xcode-General-Device Orientation進(jìn)行選擇可以進(jìn)行的旋轉(zhuǎn)方向。
    *另一個就是代碼去控制

Appdelegate.m類里面進(jìn)行生命周期添加方法
Appdelegate.h添加屬性isShouAutoRotate-BOOL值
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.isShouAutoRotate == 1) {
return UIInterfaceOrientationMaskLandscape;
}else{
return (UIInterfaceOrientationMaskPortrait);
}
}

//可以添加這個,設(shè)置是否可以進(jìn)行橫豎屏旋轉(zhuǎn)
//一般情況下子類界面進(jìn)行橫豎屏旋轉(zhuǎn)就重寫方法就好了,不需要在這里面添加了
//- (BOOL)shouldAutorotate
//{
// if (self.isShouAutoRotate == 1) {
// return YES;
// }
// return NO;
//}

Appdelegate.m進(jìn)行設(shè)置全局的橫豎屏。

在需要的控制器里面進(jìn)行添加,我們項(xiàng)目是視頻類App,需求就是進(jìn)行橫豎屏界面的旋轉(zhuǎn),進(jìn)入就是橫屏模式。
number=1 可以旋轉(zhuǎn),左右可以進(jìn)行旋轉(zhuǎn)
number=0 禁止旋轉(zhuǎn)

這是ios6之后新增的一組枚舉值,使用組合時更加方便,使用時根據(jù)返回值類型選擇正確的格式。這個屬性最管用,其余的倆個不是很好用。
/*typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) {
UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
} */

  • (void)appdelegateisShouAutoRotate:(int)number
    {
    AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appdelegate.isShouAutoRotate = number;
    }

  • (BOOL)shouldAutorotate
    {
    return ?;
    }
    第一個方法不是很建議使用.代碼進(jìn)行控制是最方便的。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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