[英]Change view controller on device rotation
我正在研究我的第一个Xcode项目,我想知道是否可以有2个视图控制器,一个具有纵向视图,第二个具有水平视图。 有什么方法可以将这两个视图控制器连接起来,这样当设备旋转时,视图会发生变化吗?
在viewDidLoad中,将旋转的视图添加到superview,并使用对象向UIDeviceOrientationDidChangeNotification注册观察者:[UIDevice currentDevice]。 在选择器上设置其框架。 然后旋转新的旋转视图,并将旧视图的alpha设置为0.0
- (void)deviceOrientationChangedNotification:(NSNotification *)notification
{
UIDevice *device = [notification object];
UIDeviceOrientation orientation = device.orientation;
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
{
[rotatedView setTransform:CGAffineTransformMakeRotation(M_PI_2)];
rotatedView.frame = [UIScreen mainScreen].bounds;
oldView.alpha = 0.0;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.