我指的是DMD Panorama应用程序。
如您所见,此图像的顶部有一个阴阳符号。
旋转设备后,两个符号会更接近,如下所示:
您能告诉我如何检测设备的旋转情况,以便在设备旋转时,这两个图像更接近?
感谢您的回复。
答案 0 :(得分:5)
在viewWillAppear函数中添加通知程序
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];}
方向更改通知此功能
- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}
进而调用此函数处理moviePlayerController框架的方向
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//load the portrait view
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//load the landscape view
}}
在viewDidDisappear中删除通知
-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];}
答案 1 :(得分:1)
首先注册通知
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectDeviceOrientation) name:UIDeviceOrientationDidChangeNotification object:nil];
然后添加此方法
-(void) detectDeviceOrientation
{
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight))
{
// Landscape mode
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait)
{
// portrait mode
}
}
答案 2 :(得分:0)
在加载应用程序或加载视图时尝试执行以下操作:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
然后添加以下方法:
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
/* set frames for images */
break;
case UIDeviceOrientationPortraitUpsideDown:
/* set frames for images */
break;
default:
break;
};
}
以上内容可让您注册设备的方向更改,而无需启用视图的自动旋转。