我在导航控制器中有一个子视图,当ipad模拟器旋转为纵向或横向时,主视图是自动旋转适合ipad方向,但子视图不是。子视图也是旋转的,但不适合ipad方向,子视图方向始终朝向ipad主页按钮。
我的问题是,如何使子视图自动旋转并具有主视图方向的方向???
有些人可以帮助我,请...
答案 0 :(得分: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);
}
}
最后,问题解决了。 this是帮助我的链接。