Các viewWillTransitionToSize:withTransitionCoordinator:
dường như chỉ làm việc nếu giao diện được thực sự sẽ thay đổi kích thước, có nghĩa là chúng tôi đã xoay 90 độ. Nếu bạn có một mặt nạ trên bố trí của bạn mà chỉ cho phép cảnh quan, khi xoay 180 độ, kích thước giao diện không thay đổi, do đó, phương pháp này dường như không được gọi.
Tôi đã làm việc xung quanh này trong ứng dụng của mình bằng cách thay vì đăng ký vào UIDeviceOrientationDidChangeNotification
thông báo như sau:
(Theo quan điểm điều khiển của tôi viewWillAppear
):
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
(An của tôi viewWillDisappear
[nhớ để bỏ đăng ký])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
My deviceOrientationDidChange:
trông giống như:
- (void)deviceOrientationDidChange:(NSNotification *)notification {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self willRotateToInterfaceOrientation:orientation duration:1.0];
}
tôi đã tải viewController của tôi như là một cái nhìn cho các nút phân đoạn. Trong trường hợp này tôi đã không nhận được viewWillTransitionToSize: withTransitionCoordinator: được gọi. Bạn đang cố gắng tải viewController như thế nào? – Surendra