![](/img/trans.png)
[英]UIDeviceOrientation for MPMoviePlayerViewController
[英]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 duration:(NSTimeInterval)duration {
但是在更改播放列表时已经在横向或纵向中不起作用。
而不是使用[[UIDevice currentDevice] orientation]来检查方向,使用状态栏方向来获得精确的方向。
UIDeviceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
要避免警告,请使用:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
你总是得到风景,因为这是你的默认(来自你的if语句)。 如果您在调试器中使用断点,那么您将看到报告的方向是Unknown 。
实际上,您的代码很好,但这是模拟器的限制。 如果您使用相同的代码,使用设备方向而不是接口方向,如果您在物理设备上使用它,您将获得实际值,这可以由您拥有的if语句驱动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.