0
我有一個應用程序可以播放來自網絡服務器的視頻,但它只是以橫向播放。我希望我的應用程序使用加速度計以橫向和縱向方向播放我的視頻。我希望我的視頻播放功能看起來像iPhone中的YouTube應用程序。任何人都可以請幫助我如何做到這一點?謝謝在我的電影播放器應用程序中使用加速度計
我有一個應用程序可以播放來自網絡服務器的視頻,但它只是以橫向播放。我希望我的應用程序使用加速度計以橫向和縱向方向播放我的視頻。我希望我的視頻播放功能看起來像iPhone中的YouTube應用程序。任何人都可以請幫助我如何做到這一點?謝謝在我的電影播放器應用程序中使用加速度計
爲此,你不需要加速度計。相反,您可以聽取來自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;
}
}