我有一个应用程序可以播放来自网络服务器的视频,但它只能横向播放。我希望我的应用使用加速度计以横向和纵向播放视频。我希望我的视频播放功能看起来像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;
}
}
关于iphone - 在我的Movieplayer应用程序中使用加速度计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8570221/