Liz*_*zza 48 iphone cocoa-touch rotation ios ios6
我一直在网上寻找解决方案,但一无所获.我正在尝试使我的iOS 5应用iOS 6兼容.我无法让定位的东西正常工作.我无法检测到旋转何时发生.这是我正在尝试的代码:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
// pre-iOS 6 support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)
新的supportedInterfaceOrientation:方法被调用就好了.但是,shouldAutorotate方法不会触发.我需要在旋转时进行一些图像交换,但我无法得到旋转即将发生的任何迹象.
提前致谢.
use*_*376 80
查看您的应用程序启动时是否收到以下错误.
应用程序窗口应在应用程序启动结束时具有根视图控制器
如果是这样,修复它的方法是在AppDelegate.m
文件中进行以下更改(尽管似乎有很多答案如何解决这个问题):
// Replace
[self.window addSubview:[navigationController view]]; //OLD
// With
[self.window setRootViewController:navigationController]; //NEW
Run Code Online (Sandbox Code Playgroud)
在此之后shouldAutoRotate
应该正确调用.
Mik*_*ard 45
当使用UINavigationController作为应用程序的基础时,我使用以下子类给予我灵活性,允许最顶层的子视图控制器决定旋转.
@interface RotationAwareNavigationController : UINavigationController
@end
@implementation RotationAwareNavigationController
-(NSUInteger)supportedInterfaceOrientations {
UIViewController *top = self.topViewController;
return top.supportedInterfaceOrientations;
}
-(BOOL)shouldAutorotate {
UIViewController *top = self.topViewController;
return [top shouldAutorotate];
}
@end
Run Code Online (Sandbox Code Playgroud)
bor*_*den 15
该方法不是确定该方法的正确方法.正确的方法是willRotateToInterfaceOrientation:duration:
应该旋转到方向(而不是shouldAutorotate)方法已被弃用,并且从iOS 6开始将不再被调用,但它无论如何都不会以您使用它的方式使用.
编辑对重复的downvotes的回应.请解释为什么使用我指出的方法不是(引用OP)"指示即将发生轮换".问题和标题的内容不匹配.
Adr*_*ian 10
看起来在iOS 6上,容器导航控制器在旋转时不会查询子视图控制器:
现在,iOS容器(例如UINavigationController)不会咨询他们的孩子以确定他们是否应该自动旋转.默认情况下,应用程序和视图控制器支持的界面方向设置为iPad惯用语的UIInterfaceOrientationMaskAll和iPhone惯用语的UIInterfaceOrientationMaskAllButUpsideDown.
这种行为很容易测试.我所做的是使用相同的自定义视图控制器
在第一种情况下,一切都是在自定义导航控制器中通过组合决定的,shouldAutorotate
并且与supportedInterfaceOrientations
给定supportedInterfaceOrientations
的应用程序支持的方向一致.
在第二种情况下,即使supportedInterfaceOrientations
UIPageViewController调用自定义视图控制器,也不会考虑返回值.如果在UIPageViewController的子类中覆盖这两个方法,它就可以工作.我不确定它的副作用,因为这个类不应该是子类.
Bas*_*CAD 10
如果您viewController
是a的孩子viewController
,UINavigationController
那么您可以执行以下操作:
UINavigationController
shouldAutoRotate
在子类中覆盖topViewController
调用此方法时发送此消息//此方法位于您的UINavigationController
子类中
- (BOOL)shouldAutorotate
{
if([self.topViewController respondsToSelector:@selector(shouldAutorotate)])
{
return [self.topViewController shouldAutorotate];
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
48261 次 |
最近记录: |