ios中可以設(shè)置是橫屏還是豎屏。但如果你在xcode中同時(shí)選擇了橫屏和豎屏,當(dāng)你旋轉(zhuǎn)屏幕時(shí),你的view就會(huì)同時(shí)就會(huì)跟著旋轉(zhuǎn)。我現(xiàn)在的問題時(shí),我的app要有兩個(gè)view,一個(gè)是支持橫屏的,但它不能選擇,永遠(yuǎn)橫屏。另外一個(gè)是豎屏的,永遠(yuǎn)是豎屏的,也不能再選擇。兩個(gè)view通過一個(gè)button關(guān)聯(lián),點(diǎn)一下,進(jìn)入另一個(gè)。
業(yè)精于勤,荒于嬉;行成于思,毀于隨。
沒地方放壓縮包,我就在這里寫個(gè)簡(jiǎn)單吧,2個(gè)UIViewController,你自己新建一個(gè)工程就加兩按鈕就可以測(cè)試。
核心需要添加的方法如下:
1,PortraitViewController 不旋轉(zhuǎn),保持豎屏
//iOS 5 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationPortrait); } //iOS 6 - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; }
LandscapeViewController 始終保持橫屏
//iOS 5 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == self.preferredInterfaceOrientationForPresentation); } //iOS 6 - (BOOL) shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)