【发布时间】:2010-11-25 05:02:44
【问题描述】:
我在导航控制器中有一个子视图,当 ipad 模拟器旋转为纵向或横向时,主视图会自动旋转以适应 ipad 方向,但子视图不是。子视图也是旋转的,但不适合 ipad 方向,子视图方向总是横向朝向 ipad 主页按钮。
我的问题是,如何使子视图自动旋转并具有像主视图的方向一样的方向???
请帮帮我...
【问题讨论】:
标签: ipad orientation autorotate
我在导航控制器中有一个子视图,当 ipad 模拟器旋转为纵向或横向时,主视图会自动旋转以适应 ipad 方向,但子视图不是。子视图也是旋转的,但不适合 ipad 方向,子视图方向总是横向朝向 ipad 主页按钮。
我的问题是,如何使子视图自动旋转并具有像主视图的方向一样的方向???
请帮帮我...
【问题讨论】:
标签: ipad orientation autorotate
我已经解决了这个问题。
我在子视图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);
}
}
终于,问题解决了。 this 是帮助我的链接。
【讨论】: