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