【问题标题】:Rotate view in simulator doesn't work模拟器中的旋转视图不起作用
【发布时间】:2011-09-11 17:36:34
【问题描述】:

在 UIViewController 实现中,我重写了 shouldAutorotateToInterfaceOrientation 方法并返回 YES(或 TRUE)。我也重写了这个方法:

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    image.frame = CGRectMake(448, 381, 128, 113);
    progresView.frame = CGRectMake(448, 498, 130, 11);
    activityIndicator.frame = CGRectMake(448, 514, 20, 20);
    statusLabel.frame = CGRectMake(473, 534, 97, 18);


} else {
    image.frame = CGRectMake(335, 643, 128, 113);
    progresView.frame = CGRectMake(335, 760, 130, 11);
    activityIndicator.frame = CGRectMake(335, 776, 20, 20);
    statusLabel.frame = CGRectMake(360, 776, 97, 18);

}

}

但是当我在模拟器或设备中播放应用程序时,旋转不起作用。它仅在纵向模式下显示。我究竟做错了什么?有什么想法吗?

附:我正在使用 XCode 4.0.2,应用程序适用于 iPad

【问题讨论】:

  • 我只是想指出,您可以使用 UIDeviceOrientationIsLandscape 宏,而不是自己检查 LandscapLeft 和 LandscapeRight。 UIKit Function Reference

标签: objective-c xcode ipad ios4 rotation


【解决方案1】:

你的意思是在 UIViewController...不是 UIView 对吗?这些方法在控制器中而不是在视图级别....

【讨论】:

  • 另外,“else”之后的一切都很好,所以方法很好。问题是它只能在纵向模式下工作。它不适用于纵向上下、横向左/右模式
  • 这是顶级视图控制器吗?
  • 因此,如果您有一个视图控制器,它有另一个视图控制器作为子视图,那么第一个将接收 shouldRotate 方法,并且需要将其传递给它的子视图。如果使用 UINavigationController 等,他们会为您处理...
  • 这可能是启动图像中的问题,因为 xcode 一直告诉我,它的大小不符合推荐的大小,但确实如此。此视图出现在启动图像之后,并且启动图像也仅适用于纵向(我不知道为什么)。此视图之后的所有其他视图都可以正常工作
  • 此视图控制器的父级在应用程序委托中:[self.window addSubview:syncView.view]; syncView 是不旋转的视图
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-07
  • 2012-11-08
  • 1970-01-01
  • 1970-01-01
  • 2011-04-07
  • 2018-04-07
  • 1970-01-01
相关资源
最近更新 更多