0

我指的是 DMD Panorama 应用程序。

如您所见,此图像的顶部有一个阴阳符号。

在此处输入图像描述

一旦我们旋转我们的设备,这两个符号就会靠近,如下所示:

在此处输入图像描述

您能否让我知道如何检测设备的旋转,以便在设备旋转时,这两个图像更接近?

感谢您的回复。

4

3 回答 3

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];}
于 2013-10-01T06:15:55.440 回答
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
    }   
}
于 2013-10-01T06:19:42.647 回答
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;
   };
}

以上将允许您注册设备的方向更改,而无需启用视图的自动旋转。

于 2013-10-01T07:29:39.387 回答