gpt4 book ai didi

ios - 在设备旋转时更改 View Controller

转载 作者:可可西里 更新时间:2023-11-01 06:17:16 25 4
gpt4 key购买 nike

我正在处理我的第一个 Xcode 项目,我想知道是否可以有 2 个 View Controller ,一个是纵向 View ,第二个是水平 View 。有什么方法可以将这 2 个 View Controller 链接起来,以便在旋转设备时 View 会发生变化?

最佳答案

在 viewDidLoad 中,将旋转 View 添加到父 View ,并使用对象:[UIDevice currentDevice] 向 UIDeviceOrientationDidChangeNotification 注册一个观察者。在选择器上设置其框架。然后旋转新的旋转 View ,并将旧 View 的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;
}
}

关于ios - 在设备旋转时更改 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28348624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com