ios – UIDeviceOrientation ipad

我有以下代码根据方向填充视图.这总是会返回景观.
- (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];
     }
}

我正确地改变了视图 – (void)animateRotation:(UIInterfaceOrientation)interfaceOrientation
持续时间:(NSTimeInterval)持续时间{
但是在更改播放列表时已经在横向或纵向中不起作用.

解决方法

而不是使用[[UIDevice currentDevice] orientation]来检查方向,使用状态栏方向来获得精确的方向.
UIDeviceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...