【发布时间】:2013-08-19 12:02:51
【问题描述】:
我有一个标志,用户将从设置中设置它。如果设置为否,则仅允许纵向。如果标志为 YES,那么纵向和横向都将被允许。 在 ios 5 及以下版本中
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
//[image_signature setImage:[self resizeImage:image_signature.image]];
if(flag == YES)
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationPortrait);
else
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
但在 ios 6 及更高版本中已弃用上述方法。 我在尝试
-(BOOL)shouldAutorotate
- (NSUInteger)supportedInterfaceOrientations
但没有成功。 请帮帮我。
编辑 我试过了。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
NSLog(@"preferredInterfaceOrientationForPresentation");
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
NSLog(@"supportedInterfaceOrientations");
return UIInterfaceOrientationMaskPortrait;
}
但只有supportedInterfaceOrientations 只被调用一次。当我改变模拟器的方向时,两种方法都没有调用。
【问题讨论】:
-
你没有删除 -(BOOL)shouldAutorotate 方法吗?
-
没有。 shouldAutorotate 返回 YES。
-
您的新代码显示您正在使用“UIInterfaceOrientationMaskPortrait”作为preferredInterfaceOrientationForPresentation 方法,而应该使用UIInterfaceOrientationPortrait。只有“supportedInterfaceOrientations”方法应该使用“mask”版本。如果标志为 YES,我以为你想要横向和纵向?
-
在 appdelegate 中,我将 rootView 设置为导航控制器。这就是它不打电话的原因。我将 viewController 设置为 rootViewController。有效。但我需要导航控制器作为 rootViewController。
-
使用额外的应用委托方法查看我的更新答案。
标签: ios orientation