iphone - 在我的Movieplayer应用程序中使用加速度计

标签 iphone youtube mpmovieplayercontroller accelerometer

我有一个应用程序可以播放来自网络服务器的视频,但它只能横向播放。我希望我的应用使用加速度计以横向和纵向播放视频。我希望我的视频播放功能看起来像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/

相关文章:

ios - 开发 iPhone 应用程序时使用的配置文件是什么?

youtube - 将您的视频管嵌入html5视频标签

javascript - YouTube API getRating "none"或 "unspecified"

php - 如何使用php提取youtube视频数据?

ios - 将 currentPlaybackTime 与 MPMoviePlayerController 一起用于 mp3 文件

iPhone 设置自动调整大小

iphone - 录制音频,添加效果,然后将结果保存到音频文件

objective-c - 我需要在iPad上播放没有声音的视频

ios - MPMoviePlayerViewController 问题

ios - 从子类别中删除应用程序?