0

我在导航控制器中有一个子视图,当 ipad 模拟器旋转为纵向或横向时,主视图自动旋转以适应 ipad 方向,但子视图不是。子视图也是旋转的,但不适合 ipad 方向,子视图方向始终是朝向 ipad 主页按钮的横向。

我的问题是,如何使子视图自动旋转并具有像主视图的方向一样的方向???

有人可以帮助我吗,拜托...

4

1 回答 1

6

我已经解决了这个问题。

我在子视图 viewController 类中使用 NSNotification 函数,在 viewWillAppear 方法中,这是我的实现:

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(deviceRotated:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];

然后,这是 deviceRotated 方法:

-(void)deviceRotated:(id)sender{
    UIDeviceOrientation orientation = [[UIDevice currentDevice]orientation];
    if (orientation == UIDeviceOrientationPortrait) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (0.0);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(0, 30);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }   
    else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 180 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(-63, -100);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }else if (orientation == UIDeviceOrientationLandscapeLeft) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 90 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(60, -180);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);


    }else if (orientation == UIDeviceOrientationLandscapeRight) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation ( M_PI * 270 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(-60, -140);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }   
}

最后,问题解决了。这是帮助我的链接

于 2011-01-18T10:19:13.837 回答