2

我是 iOS 开发的新手,我正在尝试实现一个可旋转和可调整大小的用户界面。我遇到的问题是在旋转时重新设置 UI 元素的位置。我什至无法让下面的简单代码正常工作:

- (NSUInteger)supportedInterfaceOrientations {
  return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (BOOL)shouldAutorotate {
  return YES; 
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation               
                                duration:(NSTimeInterval)duration {
  [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
      toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {        
    self.button.frame = CGRectMake(502.0, 207.0, 73.0, 44.0);
  } else {  
    self.button.frame = CGRectMake(197.0, 69.0, 73.0, 44.0);
  }
}

我已取消选择 Autoresize Subviews 选项;但是,按钮仍然在同一个位置结束。我已经记录了框架位置,它似乎具有正确的坐标,但绝对不会以这种方式结束。

4

1 回答 1

1

在实用程序检查的第一个面板中。取消选中使用自动布局。

在此处输入图像描述

于 2012-10-17T09:01:34.973 回答