代码之家  ›  专栏  ›  技术社区  ›  W Dyson

将AnimateRotationToInterfaceOrientation在一个子视图中不被调用,而另一个子视图可见并旋转

  •  1
  • W Dyson  · 技术社区  · 15 年前

    我在一个uitababarcontroller中有3个子视图。第一个选项卡的视图具有当调用willAnimateRotationToInterfaceOrientation时手动移动的对象。但是,如果旋转时另一个选项卡的视图可见,则不会调用WillAnimateRotationToInterfaceOrientation,如果我返回到第一个选项卡,则第一个选项卡视图上的项目不在正确的位置。

    当另一个视图可见时,如何在旋转时手动移动一个视图中的对象?

    1 回复  |  直到 15 年前
        1
  •  4
  •   W Dyson    15 年前

    我解决了。我所做的是创建一个方法,从viewwillappear调用,它获取当前方向并更改为屏幕上的对象位置。

    希望这能帮助别人。

    - (void)manuallyMoveViewObjects{
    
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        CGRect buttonFrame = CGRectMake(125.0, 223.0, 70.0, 50.0);
    
        self.button.frame = buttonFrame;
    }
    
    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        CGRect gbuttonFrame = CGRectMake(205.0, 131.0, 70.0, 50.0);
        self.button.frame = buttonFrame;
    
    }
    

    }