Tôi đang phát triển ứng dụng iOS có SDK mới nhất.Định hướng ngang nhưng giá trị khung dọc?
Tôi đã đặt Hướng ngang đúng hướng là hướng duy nhất có sẵn và tôi có câu hỏi về chế độ xem Chế độ xem.
Đây là mã của tôi:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != AVCaptureVideoOrientationLandscapeRight);
}
- (void)deviceOrientationDidChange:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == AVCaptureVideoOrientationLandscapeLeft)
NSLog(@"Orientation: Landscape Left");
else if (orientation == AVCaptureVideoOrientationLandscapeRight)
NSLog(@"Orientation: Landscape Right");
NSLog(@"FRAME: %@", NSStringFromCGRect(self.view.frame));
}
Và đây là nhật ký mà tôi nhận được:
Orientation: Landscape Right
FRAME: {{0, 0}, {320, 568}}
Orientation: Landscape Right
FRAME: {{0, 0}, {320, 568}}
Câu hỏi của tôi là về {{0, 0}, {320, 568}}
:
Tại sao tôi lại nhận được những giá trị?
Tôi nghĩ giá trị chính xác sẽ là {{0, 0}, {568, 320}}
.
tôi đoán là một videocontroller độ toàn màn hình của nó bạn đang hiển thị, trong khi ứng dụng vẫn ở chế độ dọc. –
Tôi đã thử nghiệm chương trình bằng trình mô phỏng và nó xuất hiện theo hướng ngang bên phải. Và có, nó là một ứng dụng toàn màn hình. – VansFannel
Bạn không nên nghe những thay đổi định hướng thiết bị. 'UIViewController' có các phương thức thích hợp để nghe các thay đổi định hướng giao diện. Thêm mã đăng nhập của bạn vào các phương pháp thích hợp đó. Hãy thử 'didRotateFromInterfaceOrientation:' hoặc 'viewDidLayoutSubviews'. – rmaddy