Đây là một quan sát nhiều hơn bất cứ điều gì, bởi vì tôi dường như đã tìm thấy một công việc xung quanh ...[UIDevice currentDevice] .orientation == UIDeviceOrientationUnknown sau UINavigationController đẩy
Đoạn code dưới đây không làm việc khi nó trong một bộ điều khiển đã được đẩy lên một ngăn xếp UINavigationController. Trong trường hợp này, [UIDevice currentDevice].orientation
liên tục trả về UIDeviceOrientationUnknown
.
-(void)layoutAccordingToOrientation {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
NSLog(@"layoutAccordingToOrientation/orientation==%i", orientation);
if (UIInterfaceOrientationIsLandscape(orientation)) {
:
_detailToolbar.frame = CGRectMake(0, 660, 1024, 44);
} else {
:
_detailToolbar.frame = CGRectMake(0, 916, 768, 44);
}
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self layoutAccordingToOrientation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Cuộc gọi sau đã được thực hiện:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Để làm việc xung quanh UIDeviceOrientationUnknown
-problem này, bây giờ tôi sử dụng sau đây thay vì:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
etc.
} else {
etc.
}
... trong đó hoạt động mỗi lần.
Tuy nhiên, tôi không thấy lý do tại sao biến thể đầu tiên sẽ không hoạt động trong ngữ cảnh của trình điều khiển chế độ xem được đẩy. Ý tưởng bất cứ ai? Nó chỉ đơn giản là một lỗi?
Tôi gặp vấn đề tương tự, tuy nhiên tôi không thể làm việc xung quanh bạn để làm việc trong tình huống của mình. – Flea