Ipad iOS 5多故事板旋转

Ipad iOS 5多故事板旋转,ipad,ios5,rotation,storyboard,Ipad,Ios5,Rotation,Storyboard,我有一个iPad应用程序,它有两个视图,每个视图都有自己的视图控制器。苹果表示,他们建议iPad应用程序能够全方位旋转。我使用此技术在旋转更改时定位故事板中的元素: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { //[super willRotateToInterfaceOrientati

我有一个iPad应用程序,它有两个视图,每个视图都有自己的视图控制器。苹果表示,他们建议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放在横向视图控制器1上,按下按钮显示视图控制器2时,问题出现了,视图控制器2显示得很好,但处于纵向模式。如果我处于视图控制器2的横向模式并转到视图控制器1,也会发生同样的情况。如果我处于纵向模式,则两种视图都可以

当我切换视图时,视图知道设备所处的方向并相应地旋转,我如何做到这一点


谢谢

您需要添加一个viewWillExample方法,如下所示:

- (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 {
    ...
}
}