旋转方向时重置帧

时间:2012-07-05 16:21:52

标签: frame landscape bounds portrait

我有一个应用程序,它有一些按钮,文本视图和标签。我想旋转设备并将它们重新绘制在屏幕上以适应。我想以编程方式进行。目前我有这些方法:

    -(void)willRotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation 
                               duration:(NSTimeInterval)duration {

    [super willRotateToInterfaceOrientation:toInterfaceOrientation  
                                   duration:duration];

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        [self reOrderSideways];
    } else {
        [self reOrderUpDown];
    }
}

-(void)reOrderSideways{
    self.viewLabel.frame=CGRectMake(175.0,140.0,130.0,20.0);
    self.buttonOne.frame=CGRectMake(20.0,20.0,440.0,100.0);
    self.buttonTwo.frame=CGRectMake(20.0,180.0,440.0,100.0);
    self.textContent.frame=CGRectMake(20.0, 290.0, 440.0, 100.0);
    self.theScroller.contentSize = CGSizeMake(480.0, 350.0);
}

-(void)reOrderUpDown{
    self.viewLabel.frame=CGRectMake(95.0,15.0,130.0,20.0);
    self.buttonOne.frame=CGRectMake(20.0,50.0,280.0,190.0);
    self.buttonTwo.frame=CGRectMake(20.0,250.0,280.0,190.0);
    self.textContent.frame=CGRectMake(20.0, 450.0, 280.0, 190.0);
    self.theScroller.contentSize = CGSizeMake(320.0, 460.0);
}

它不太有用,因为当我侧身旋转时,按钮和标签以及textview会在右侧切断。我检查了它,看起来它使用我给它的坐标,但它仍然使用肖像框架或边界。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

请尝试使用willAnimateRotationToInterfaceOrientation: