Как этого добиться в iOS?

Я имею в виду приложение DMD Panorama.

Как видите, в верхней части изображения есть символ Инь-янь.

введите описание изображения здесь

Когда мы вращаем устройство, два символа сближаются, как показано ниже:

введите описание изображения здесь

Не могли бы вы сообщить мне, как мне определить вращение устройства, чтобы при повороте устройства эти два изображения приближались?

Я ценю твой ответ.


person meetpd    schedule 01.10.2013    source источник
comment
Если вам нужно только вращение устройства, см. Этот ответ stackoverflow.com / questions / 3005389 /   -  person Amitabha    schedule 01.10.2013


Ответы (3)


Добавить уведомитель в функцию 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];}
person Vivek Sehrawat    schedule 01.10.2013
comment
Спасибо, Вивек. Позвольте мне проверить, и я свяжусь с вами. - person meetpd; 01.10.2013

сначала вы регистрируетесь для уведомления

[[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
    }   
}
person Amitabha    schedule 01.10.2013

Попробуйте сделать следующее, когда приложение загружается или когда загружается ваше представление:

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

Вышеупомянутое позволит вам зарегистрироваться для изменения ориентации устройства без включения автоповорота вашего обзора.

person Purva    schedule 01.10.2013