2013-10-01 62 views
0

我指的是DMD Panorama應用程序。如何在iOS中實現這一點?

正如你所看到的,這張圖片的頂部有一個陰陽符號。

enter image description here

一旦我們轉動我們的設備,這兩個符號走近,象下面這樣:

enter image description here

能否請你告訴我,我怎樣檢測裝置的旋轉,這樣,當設備旋轉,這兩個圖像靠近?

我很感謝您的回覆。

+0

如果你只需要設備旋轉,然後看到這個答案http://stackoverflow.com/questions/3005389/detecting-rotation-to-landscape-manually – Amitabha

回答

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

in viewDidDisappear刪除通知

-(void)viewDidDisappear:(BOOL)animated{ 
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];} 
+0

謝謝Vivek。讓我檢查,我會回到你身邊。 – meetpd

+0

vivek sehrawat不錯 – akash

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

以上將讓您無需使您的視圖的自動旋轉的設備朝向的變化登記。