在我的电影播放器应用中使用加速度计 [英] Use accelerometer in my movieplayer app
问题描述
我有一个应用程序可以播放来自网络服务器的视频,但它只能横向播放.我希望我的应用使用加速度计以横向和纵向播放视频.我希望我的视频播放功能看起来像iPhone中的youtube应用.谁能帮我怎么做?谢谢
I had an app which plays videos from a web server but it just plays in landscape orientation. I want my app to use the accelerometer to play my videos both in landscape and in portrait orientation. I want my video playback feature to look like the youtube app in the iPhone. Can anyone please help me how to do this? thanks
推荐答案
为此,您不需要加速计.取而代之的是,您侦听方向更改时从UIDevice单例实例发送的通知.在应用程序didFinishLaunching withOptions"方法中,键入以下内容:
For this you do not need the accelerometer. Instead you listen to the notifications from the UIDevice singleton instance that are sent when the orientation changes. In your "application didFinishLaunching withOptions" method, type this:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange) name: UIDeviceOrientationDidChangeNotification object: nil];
然后创建此方法来处理方向更改:
then create this method to handle the orientation change:
- (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;
}
}
这篇关于在我的电影播放器应用中使用加速度计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!