iOS螢幕旋轉之Apple Document(蘋果文件翻譯)
應用場景一:指定UIViewController支援旋轉或不旋轉
實現方法如下:
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
文件說明:UIViewController
物件屬性supportedInterfaceOrientations
,返回所支援的橫豎屏的型別。
宣告
@property(nonatomic, readonly) UIInterfaceOrientationMask supportedInterfaceOrientations;
返回值
返回當前ViewController需要被支援的方向。這個值是一個列舉型別UIInterfaceOrientationMask
,它包含了ViewController支援的旋轉方向。具體的取值如下:
typedef enum UIInterfaceOrientationMask : NSUInteger {
UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight)
} UIInterfaceOrientationMask;
UIInterfaceOrientationMask
簡介:該方法在iOS8之後被新增的,會讓你更得心應手的使用UITraitCollection
、UITraitEnvironment
APIs,在Size Class
中也支援了這些屬性,也無需再依據UIInterfaceOrientation
來確定你的ViewController所支援的方向。
在iOS8之前的版本中,你應該在supportedInterfaceOrientationsForWindow:
方法中返回一個對應的值,來確定你ViewController的方向。這裡不展開講解。
注意
當shouldAutorotate
方法的返回值設為YES
時,也就是當前控制器需要支援隨裝置旋轉,那麼當改變裝置的方向時,系統會在rootViewController
,也就是keyWindow
的rootViewController
中呼叫supportedInterfaceOrientations
方法,舉個工程中常用的例子,如果當前工程的keyWindow
的rootViewController
是UITabBarController
,那麼系統會在該ViewController
中呼叫supportedInterfaceOrientations
。
在控制器中重寫這個方法來返回需要支援的方向,在iPad上的預設值是UIInterfaceOrientationMaskAll
,在iPhone上預設值是UIInterfaceOrientationMaskAllButUpsideDown
。控制器在該方法中返回的方向值,實際上是取決於Info.plist
檔案或者appdelegate
的application:supportedInterfaceOrientationsForWindow:
是否配置支援旋轉。
這裡再說一下,支援螢幕旋轉的info.plist
檔案和appdelegate
中的方法。info.plist
的配置實際上是在工程的target->general->Deployment Info 勾選Landscape Left
和Landscape Right
即可完成配置。
如果在Appdelegate使用程式碼配置如下:
// 如
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
// iPad上需要支援所有方向
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return UIInterfaceOrientationMaskAll;
} else { /* iphone */
// iPhone上只支援豎屏
return UIInterfaceOrientationMaskPortrait ;
}
}
相關文章
- iOS螢幕旋轉解決方案iOS
- ubuntu螢幕旋轉Ubuntu
- ios一句程式碼搞定螢幕旋轉iOS
- Android 禁止螢幕旋轉Android
- orientationchange 螢幕旋轉事件事件
- 蘋果新Apple Watch曝光:體積不變 螢幕變大蘋果APP
- mui 控制旋轉螢幕方向UI
- 蘋果絕技:理解螢幕蘋果
- 有道雲詞典--翻譯/螢幕取詞翻譯
- 電腦螢幕旋轉90度怎麼復原win10 win10螢幕翻轉了怎麼辦Win10
- windows 10如何把螢幕翻轉過來_win10顯示螢幕翻轉怎麼操作WindowsWin10
- iOS 疑難雜症 — — UITableView 新增 tableFooterView 旋轉螢幕後收不到點選事件!!!...iOSUIView事件
- 蘋果iPhone XR朗讀螢幕功能怎麼用?蘋果手機文字轉語音方法教程蘋果iPhone
- Swift橫豎屏切換、自動旋轉螢幕、手動旋轉螢幕、鎖定當前螢幕禁止轉屏、橫豎屏頁面跳轉過度、橫豎屏UI適配SwiftUI
- Win10系統下怎麼禁止螢幕旋轉Win10
- [譯] 如何閱讀蘋果開發文件蘋果
- Apple裝置螢幕尺寸和方向APP
- win10平板不能自動旋轉螢幕如何解決Win10
- 瞭解Android核心元件活動生命週期————旋轉螢幕Android元件
- 【2.3.3被拒】蘋果iOS上架沒有真機提供ps製作螢幕截圖蘋果iOS
- 如何在蘋果Mac上關閉螢幕使用時間?蘋果Mac
- 文件翻譯器怎麼用?如何翻譯Word文件?
- MPAndroidChart文件翻譯Android
- iPod之父:蘋果螢幕時間功能存在很多漏洞和不足蘋果
- mimoLive直播製作軟體如何使用Apple TV捕獲iOS裝置螢幕?APPiOS
- 影像縮放、旋轉、翻轉、平移
- iOS 各種螢幕尺寸iOS
- BZOJ1757 : Apple 偷蘋果APP蘋果
- 國產OLED螢幕被認可,蘋果讓京東方獲得iPhone供應螢幕資格蘋果iPhone
- 有ppt文件翻譯軟體嗎?如何翻譯整篇ppt文件
- Moya官方文件翻譯
- 怎麼將蘋果手機螢幕投屏到電腦上蘋果
- 再見了小屏iPhone!蘋果iPhone如今追求史上最大螢幕iPhone蘋果
- Omdia: 蘋果的螢幕技術路線圖2021年 – 2023年蘋果
- 實用的Word文件翻譯方法分享,讓Word文件快速翻譯
- 怎麼翻譯整篇Excel文件?Excel文件翻譯一招搞定Excel
- iOS中的螢幕導航iOS
- iOS 螢幕錄製實現iOS
- iOS ReplayKit 與 螢幕錄製iOS