0
我曾嘗試使用下面的代碼如何在iOS中返回前臺時更改設備方向?
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
從縱向方向更改爲子視圖控制器的風景,但是當我去到後臺,並返回到前臺,然後我按下按鈕轉到主頁,然後需要改變使用下面的代碼
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([ConfigObjC currentPage] && [[ConfigObjC currentPage] isEqualToString:@"SubViewController"])
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
else{
return UIInterfaceOrientationMaskPortrait;
}
}
,但它不能正常工作從橫向到縱向。
我已經成功地改變從風景到肖像的方向,當我不去背景。通過編碼是
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
另一種方法:我怎樣才能解決這個問題,非常感謝
我已經做了使用下面的代碼的方向NSNumber * value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; [[UIDevice currentDevice] setValue:value forKey:@「orientation」];但是當我轉到背景並返回到前景時,我嘗試使用NSNumber * value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]將方向更改爲Portrait。 [[UIDevice currentDevice] setValue:value forKey:@「orientation」];它不起作用 – vincent
UIDeviceOrientation是隻讀的,UIInterfaceOrientation是readwrite。您可以使用UIDeviceOrientation註冊通知,然後旋轉屏幕以及查看 – SeraZheng