[英]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.