【问题标题】:iOS 5 Multi Storyboard RotationiOS 5 多故事板旋转
【发布时间】:2012-03-08 13:26:47
【问题描述】:

我有一个 iPad 应用程序,它有 2 个视图,每个视图都有自己的视图控制器。苹果表示,他们建议 iPad 应用程序能够向各个方向旋转。我使用这种技术来定位我的故事板中的元素旋转变化:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    //[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        studentNumberButton.frame = CGRectMake(30, 1, 158, 155);
        studentNumberLabel.frame = CGRectMake(173, 57, 347, 43);
        studentLabel.frame = CGRectMake(528, 56, 67, 43);

        // Other code goes below...

我为每个视图都这样做了,它适用于所有旋转。然而,当我说,让 iPad 在 View Controller 1 上以横向显示并按下按钮以显示 View Controller 2 时,问题就出现了,View Controller 2 出现得很好,但处于纵向模式。如果我处于 View Controller 2 的横向模式并转到 View Controller 1,也会发生同样的情况。如果我处于纵向模式,两个视图的一切都很好。

我怎样才能做到这一点,当我切换视图时,视图知道设备的方向并相应地旋转?

谢谢!

【问题讨论】:

    标签: ipad ios5 rotation storyboard


    【解决方案1】:

    你需要添加一个viewWillAppear方法如下:

    - (void)viewWillAppear:(BOOL)animated {
    if (([self interfaceOrientation] == UIDeviceOrientationLandscapeLeft)|| ([self interfaceOrientation] == UIDeviceOrientationLandscapeRight)) {
    
        studentNumberButton.frame = CGRectMake(30, 1, 158, 155);
        studentNumberLabel.frame = CGRectMake(173, 57, 347, 43);
        studentLabel.frame = CGRectMake(528, 56, 67, 43);
        ...
    
    } else {
        ...
    }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-10
      • 2012-08-22
      • 2013-10-09
      • 2013-06-05
      • 2012-06-17
      • 1970-01-01
      • 2012-10-11
      • 2013-05-01
      相关资源
      最近更新 更多