[英]Change Orientation in iOS 9
我的應用程序將在橫向啟動,只有一個視圖可以更改為縱向,其中有一個按鈕,我單擊此按鈕將方向更改為縱向。 它在iPad(iOS 8.4,部署目標:7.0)上按預期執行,我制作了一個iPhone版本,我在UI上做了一些調整,它在iPhone 6 Plus模擬器上運行(Base SDK:9.1,部署目標: 7.0),但是chagning方向按鈕不起作用。 我想知道如何在iOS 9中實現這一點; 以下是我的代碼:
- (void)changeOrientation
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation==UIInterfaceOrientationLandscapeLeft||orientation==UIInterfaceOrientationLandscapeRight){
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
if (orientation==UIInterfaceOrientationLandscapeLeft) {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
}else {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
}
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ScreenToPortrait" object:nil];
}else{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
if (orientation==UIInterfaceOrientationPortrait) {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
}else {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
}
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ScreenToLandscapeLeft" object:nil];
}
[UIViewController attemptRotationToDeviceOrientation];
}
這適用於iOS9
NSNumber *orientationValue = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue: orientationValue forKey:@"orientation"];
General
選項卡,然后啟用所有方向。 supportedInterfaceOrientations()
並返回橫向方向值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.