我有以下视图层次结构
实际上,有一个根ScrollView控制器,它有多个子ScrollViews。(根ScrollViewController只向水平滚动-子只垂直滚动)。每个子ScrollView都有一个UIViewController。
我的根ScrollView控制器按预期工作,并调用我的旋转方法,如下所示:
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self rotateScrollViewToInterfaceOrientation:toInterfaceOrientation];
}
- (void) rotateScrollViewToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
// do some rotation logic
}
}我在我的Sub、ScrollViews和UIViewControllers中使用了相同的方法,但是它们在旋转时不会被调用。
有人知道为什么吗?
发布于 2012-11-23 13:37:09
不推荐使用shouldAutorotateToInterfaceOrientation方法,并且将不再在iOS 6中调用该方法。
尝试实现以下方法。
-(BOOL)shouldAutomaticallyForwardAppearanceMethods{
// This method is called to determine whether to
// automatically forward appearance-related containment
// callbacks to child view controllers.
return YES;
}
-(BOOL)shouldAutomaticallyForwardRotationMethods{
// This method is called to determine whether to
// automatically forward rotation-related containment
// callbacks to child view controllers.
return YES;
}注意: iOS 6中刚刚支持这些方法。
发布于 2012-11-23 13:34:39
来自iOS 6.0发行说明:
自转在iOS 6中发生变化,在iOS 6中,不推荐使用shouldAutorotateToInterfaceOrientation: UIViewController方法。取而代之的是,您应该使用supportedInterfaceOrientationsForWindow:和shouldAutorotate方法。更多的责任转移到应用程序和应用程序委托。现在,iOS容器(如UINavigationController)不会咨询它们的子容器来确定它们是否应该自动访问。默认情况下,应用程序和视图控制器支持的接口方向被设置为UIInterfaceOrientationMaskAll ( iPad成语)和UIInterfaceOrientationMaskAllButUpsideDown ( iPhone成语)。视图控制器支持的接口方向可以随时间而改变--甚至应用程序支持的接口方向也会随着时间的推移而改变。当设备旋转时,系统要求最顶层的全屏视图控制器(通常是根视图控制器)提供其支持的接口方向,或者当视图控制器呈现全屏模式表示风格时。此外,只有当此视图控制器从其shouldAutorotate方法返回YES时,才会检索所支持的方向。系统将视图控制器的支持方向与应用程序支持的方向(由Info.plist文件或应用程序委托的Info.plist方法确定)交叉,以确定是否旋转。系统通过将应用程序的supportedInterfaceOrientationsForWindow:方法返回的值与顶部最全屏控制器的supportedInterfaceOrientations方法返回的值相交来确定是否支持方向。setStatusBarOrientation:动画:方法并不是完全不推荐的。现在,只有当顶部最全屏视图控制器的supportedInterfaceOrientations方法返回0时,它才能工作。这使得调用方负责确保状态栏方向是一致的。为了兼容性,仍然实现shouldAutorotateToInterfaceOrientation:方法的视图控制器不会获得新的自动恢复行为。(换句话说,它们不会回到使用应用程序、应用程序委托或Info.plist文件来确定所支持的方向。)相反,shouldAutorotateToInterfaceOrientation:方法用于合成将由supportedInterfaceOrientations方法返回的信息。
https://stackoverflow.com/questions/13530020
复制相似问题