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