【问题标题】:How to achieve this in iOS?如何在 iOS 中实现这一点?
【发布时间】:2013-10-01 06:10:28
【问题描述】:

我指的是 DMD Panorama 应用程序。

如您所见,这张图片的顶部有一个阴阳符号。

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

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

感谢您的回复。

【问题讨论】:

标签: iphone ios objective-c cocoa-touch panoramas


【解决方案1】:

在 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];}

【讨论】:

  • 谢谢维韦克。让我检查一下,我会尽快回复您。
【解决方案2】:

首先你注册通知

[[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
    }   
}

【讨论】:

    【解决方案3】:

    在应用程序加载或视图加载时尝试执行以下操作:

    [[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;
       };
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多