Я не пробовал этого, но я бы начал так: Прослушайте изменения ориентации ...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
При изменении на ландшафт представьте альбом vc.При изменении на портрет, отклоните его ...
- (void)orientationDidChange:(NSNotification *)notification {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsPortrait(orientation) && self.presentedViewController) {
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
} else if (UIInterfaceOrientationIsLandscape(orientation) && !self.presentedViewController) {
MyLandscapeVC *landscapeVC = [[MyLandscapeVC alloc] initWithNibName:@"MyLandscapeVC" bundle:nil]; // or however you make this
[self presentViewController:landscapeVC animated:YES completion:nil];
}
}
Дополнительная проверка для self.presentedViewController
состоит в том, чтобы предотвратить любую неровность в системе во время быстрых вращений назад и вперед, поэтому мы никогда не получаем больше одного изVCS пейзаж сложены.Это может быть ненужным.
Это можно изолировать в одном файле с помощью категории классов в UIViewController, например так ...
// in UIViewController+Rotations.h
@interface UIViewController (Rotations)
- (void)observeRotations;
@end
// in UIViewController+Rotations.m
#import "UIViewController+Rotations.h"
@implementation UIViewController (Rotations)
- (void)observeRotations {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationDidChange:(NSNotification *)notification {
// etc., from above
}
@end
Просто импортируйте UIViewController + Rotations.h в контроллеры видаи в начале жизненного цикла (вероятно, viewWillAppear) вызов [self observeRotations];