简体   繁体   English

在目标iOS 5.1上以xcode 4.6.2运行的iOS 5.1 App是否无法限制某些视图的方向?

[英]iOS 5.1 App running with xcode 4.6.2 with target iOS 5.1, not able to restrict some views from orientation?

I developed an app with Xcode 4.4 and iOS 5.1. 我使用Xcode 4.4和iOS 5.1开发了一个应用程序。 I updated Xcode to 4.6.2 and iOS is 6.1, but I have selected the target as iOS 5.1 (even though I am using Xcode 4.6.2). 我将Xcode更新为4.6.2,iOS为6.1,但我已将目标选择为iOS 5.1(即使我使用的是Xcode 4.6.2)。 My app supports all orientations. 我的应用程序支持所有方向。

My question is: I want to restrict some views in landscape mode, it is working fine in the simulator but when I am running the app in iPhone 5 device, my methods are not working, kindly help me? 我的问题是:我想在横向模式下限制某些视图,它在模拟器中可以正常工作,但是当我在iPhone 5设备上运行该应用程序时,我的方法不起作用,请帮帮我吗?

In your view controller(s) where you want to restrict your orientation I would do the following: 在您要限制方向的视图控制器中,我将执行以下操作:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return interfaceOrientation == UIInterfaceOrientationLandscape;
}

Regarding your iPhone 5 the shouldAutorotateToInterfaceOrientation was deprecated with iOS6 so you're going to have to do an OS check and implement/override the supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation methods instead. 关于你的iPhone 5的shouldAutorotateToInterfaceOrientation与iOS6的弃用所以你将不得不做一个OS检查和落实/覆盖supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation方法来代替。

I use this in my app and it works perfect! 我在我的应用程序中使用了它,效果很好!

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

When you want a view only for portrait use this: 当您只需要纵向视图时,请使用以下命令:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM