[英]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.