简体   繁体   English

UIDeviceOrientation ipad

[英]UIDeviceOrientation ipad

I have the following code to fill a view according to the orientation. 我有以下代码根据方向填充视图。 This always returns landscape. 这总是会返回景观。

- (void)setData:(BCPlaylist *)list  {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown){
      NSLog(@"portrait");
      [self setPlaylist:list];
      [self renderPlaylist];
      [activity stopAnimating];
    }else{
      NSLog(@"landscape");
      [self setPlaylist:list];
      [self renderPlaylistOne];
      [activity stopAnimating];
     }
}

I change views correctly in - (void)animateRotation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { But that doesn't work when already in landscape or portrait when changing a playlist. 我正确地更改了视图- (void)animateRotation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {但是在更改播放列表时已经在横向或纵向中不起作用。

而不是使用[[UIDevice currentDevice] orientation]来检查方向,使用状态栏方向来获得精确的方向。

    UIDeviceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

要避免警告,请使用:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

You'd always get landscape, because that's your default (from your if statement). 你总是得到风景,因为这是你的默认(来自你的if语句)。 If you walk through the debugger with a breakpoint there, you'll see that the orientation reported is that of Unknown . 如果您在调试器中使用断点,那么您将看到报告的方向是Unknown

In fact, your code is fine, but this is a limitation of the simulator. 实际上,您的代码很好,但这是模拟器的限制。 If you take the same code, using Device orientation and not Interface orientation, you'll get actual values if you use it on the physical device, which can be driven by the if-statement you have. 如果您使用相同的代码,使用设备方向而不是接口方向,如果您在物理设备上使用它,您将获得实际值,这可以由您拥有的if语句驱动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于MPMoviePlayerViewController的UIDeviceOrientation - UIDeviceOrientation for MPMoviePlayerViewController UIDeviceOrientation通知 - UIDeviceOrientation Notifications 使用NSNotificationCenter和UIDeviceOrientation更改方向 - Change orientation with NSNotificationCenter and UIDeviceOrientation iOS:UIDeviceOrientation 未按预期工作 - iOS: UIDeviceOrientation is not working as intended 什么是UIDeviceOrientation和UIInterfaceOrientation的Android等价物? - What is the Android equivalent of UIDeviceOrientation and UIInterfaceOrientation? UIDeviceOrientation 在 Swift 中以纵向模式提供横向方向 - UIDeviceOrientation giving landscape orientation in Portrait mode in Swift 使用UIDeviceOrientation更改通知而不是viewillTransistionToSize - Using UIDeviceOrientation change notification instead of viewillTransistionToSize 从枚举类型'enum UIDeviceOrientation'到不同的枚举类型'UIInterfaceOrientation''enum UIInterfaceOrientation的隐式转换 - Implicit conversion from enumeration type 'enum UIDeviceOrientation' to different enum type 'UIInterfaceOrientation' 'enum UIInterfaceOrientation 首次解锁手机后,如何使UIDeviceOrientation自动成为肖像? - How to make UIDeviceOrientation from automatically becoming portrait when phone is first unlocked? 在iPad 1上崩溃但不是> iPad 1 - sizeof crashing on iPad 1 but not > iPad 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM