我想複製本機相機應用程序的確切行爲(包括其導航到畫廊和回)在設備旋轉時,UI控件旋轉的地方,而不是整個屏幕旋轉。我能夠通過鎖定在肖像模式屏幕和手動搬運設備旋轉的通知這樣的複製旋轉行爲:相機應用程序如屏幕旋轉和導航
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (void)orientationDidChange:(NSNotification*)note {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
UIInterfaceOrientation newOrientation = UIInterfaceOrientationPortrait;
switch (orientation) {
case UIDeviceOrientationPortraitUpsideDown:
newOrientation = UIInterfaceOrientationPortraitUpsideDown;
break;
case UIDeviceOrientationLandscapeLeft:
newOrientation = UIInterfaceOrientationLandscapeLeft;
break;
case UIDeviceOrientationLandscapeRight:
newOrientation = UIInterfaceOrientationLandscapeRight;
break;
case UIDeviceOrientationPortrait:
newOrientation = UIInterfaceOrientationPortrait;
break;
default:
newOrientation = self.currentOrientation;
break;
}
if (newOrientation == self.currentOrientation) {
return;
}
self.currentOrientation = newOrientation;
[self rotateInterfaceToOrientation:self.currentOrientation];
}
- (void)rotateInterfaceToOrientation:(UIInterfaceOrientation)orientation {
double rotationAngle = 0;
switch (orientation) {
case UIInterfaceOrientationPortraitUpsideDown: rotationAngle = M_PI; break;
case UIInterfaceOrientationLandscapeLeft: rotationAngle = M_PI_2; break;
case UIInterfaceOrientationLandscapeRight: rotationAngle = -M_PI_2; break;
default: rotationAngle = 0; break;
}
CGFloat angle = (float)rotationAngle;
self.defaultTransform = CGAffineTransformMakeRotation(angle);
... manual animation by setting transform
}
這種運作良好,準確地表現爲我所需要的。
我的問題是根據應用程序的屏幕仍然是肖像的事實。
整個應用程序支持縱向和橫向模式。當我導航到不同的屏幕並返回時,由於它從橫向視圖轉換爲縱向視圖,轉換已中斷。就在過渡動畫開始之前,前一個風景視圖將佈局更改爲肖像(雖然它被異常拉伸)。來自模擬器的視頻:http://gfycat.com/DeafeningGaseousBrant。轉換開始時您可以看到佈局更改。它在設備上更加明顯,因爲您可以一直看到屏幕。可能值得一提的是,我使用自定義過渡管理器在瀏覽時使屏幕正確朝向(這可能解釋爲什麼視圖會像移動一樣移動,但它對有問題的行爲沒有影響)。
此外,當我用鍵盤或UIAlertView顯示提示時,它們的方向是錯誤的。再次模擬器:http://gfycat.com/SelfreliantPointedEwe。
是否有任何方式從視圖控制器指定該視圖當前是縱向還是橫向?或者有沒有辦法讓屏幕旋轉手動,而不使用自動佈局調整大小/佈局?
我在其他問題閱讀該解決方案,但我不敢相信這是正確的方法。當使用自動佈局時,無需基於設備方向對約束進行復雜編輯,就不可能達到想要的效果。 其中一件事是,當您將設備旋轉到左側橫向時,觸發按鈕位於右側。當你將它旋轉到正確的風景時,它位於左側。這僅僅是自動佈局無法完成的。必須有一些其他的魔法發生。 – Montas