2011-12-20 3 views
0

У меня было приложение, которое воспроизводит видео с веб-сервера, но оно просто играет в альбомной ориентации. Я хочу, чтобы мое приложение использовало акселерометр для воспроизведения моих видеороликов как в пейзажной, так и в портретной ориентации. Я хочу, чтобы моя функция воспроизведения видео выглядела как приложение YouTube в iPhone. Может ли кто-нибудь помочь мне, как это сделать? спасибоИспользование акселерометра в приложении для моего видеоролика

ответ

1

Для этого вам не нужен акселерометр. Вместо этого вы прослушиваете уведомления из экземпляра singleton экземпляра UIDevice, которые отправляются при изменении ориентации. В вашем методе "приложение didFinishLaunching withOptions", введите следующее:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange) name: UIDeviceOrientationDidChangeNotification object: nil]; 

затем создать этот метод для обработки изменения ориентации:

- (void)deviceOrientationDidChange { 
int orientation = (int)[[UIDevice currentDevice]orientation]; 
switch (orientation) { 
    case UIDeviceOrientationFaceDown: 
     NSLog(@"UIDeviceOrientationFaceDown"); 
     // handle orientation 
     break; 
    case UIDeviceOrientationFaceUp: 
     NSLog(@"UIDeviceOrientationFaceUp"); 
     // handle orientation 
     break; 
    case UIDeviceOrientationLandscapeLeft: 
     NSLog(@"UIDeviceOrientationLandscapeLeft"); 
     // handle orientation 
     break; 
    case UIDeviceOrientationLandscapeRight: 
     NSLog(@"UIDeviceOrientationLandscapeRight"); 
     // handle orientation 
     break; 
    case UIDeviceOrientationPortrait: 
     NSLog(@"UIDeviceOrientationPortrait"); 
     // handle orientation 
     break; 
    case UIDeviceOrientationPortraitUpsideDown: 
     NSLog(@"UIDeviceOrientationPortraitUpsideDown"); 
     // handle orientation 
     break; 
    case UIDeviceOrientationUnknown: 
     NSLog(@"UIDeviceOrientationUnknown"); 
     // handle orientation 
     break; 

    default: 
     break; 
} 
} 
Смежные вопросы