首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为MPMoviePlayerViewController更改UIModalTransitionStyle

如何为MPMoviePlayerViewController更改UIModalTransitionStyle
EN

Stack Overflow用户
提问于 2010-09-10 23:23:38
回答 3查看 7.5K关注 0票数 2

当我使用MPMoviePlayerViewController时,我似乎无法将modalTransitionStyle更改为默认的向上滑动动画以外的任何内容。

还有没有其他人能让它正常工作呢?

代码语言:javascript
复制
MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoURL]];
theMoviePlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // doesn't work
[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-09-11 02:15:04

看着

http://www.drobnik.com/touch/2010/07/the-3-2-hurdle-of-mpmovieplayercontroller/

这里的代码似乎也将呈现MPMoviePlayerViewController实例的视图控制器的modalTransitionStyle设置为相同的值。这行得通吗?

票数 2
EN

Stack Overflow用户

发布于 2013-06-07 06:06:40

我发现使用CrossDisolve模式动画启动“MPMoviePlayerViewController”实例的方法是在导航控制器中启动电影播放器,如下所示:

代码语言:javascript
复制
NSURL * videoUrl = [[NSURL alloc] initFileURLWithPath:videoPath];
MPMoviePlayerViewController * moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoUrl];

UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:moviePlayerController];
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[navController setNavigationBarHidden:YES];

[self presentViewController:navController animated:YES completion:nil];

和listen to MPMoviePlayerPlaybackDidFinishNotification通知:

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

并在视频结束后将其关闭:

代码语言:javascript
复制
-(void)movieDidFinish:(NSNotification *)notification {

    [self dismissViewControllerAnimated:YES completion:nil];
}
票数 6
EN

Stack Overflow用户

发布于 2014-12-14 01:35:36

Ecarrion的回答非常有帮助--这是一个Swift版本,希望能节省一些时间。

代码语言:javascript
复制
import MediaPlayer

class ViewController: UIViewController {

    ...

    func playAction() {

    // setup the media player view
    var url:NSURL = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
    var moviePlayerView = MPMoviePlayerViewController(contentURL: url)
    moviePlayerView.moviePlayer.controlStyle = MPMovieControlStyle.None
    moviePlayerView.moviePlayer.repeatMode = MPMovieRepeatMode.None

    // register the completion
    NSNotificationCenter.defaultCenter().addObserver(self,
        selector: "videoHasFinishedPlaying:",
        name: MPMoviePlayerPlaybackDidFinishNotification,
        object: nil)

    // instantiate nav controller and add the moviePlayerView as its root
    var navController = UINavigationController(rootViewController:  moviePlayerView)

    // set transition (this is what overrides the animated "slide up" look
    navController?.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
    navController?.setNavigationBarHidden(true, animated: false)

    // present the nav controller
    self.presentViewController(navController!, animated: true, completion: nil)
}


func videoHasFinishedPlaying(notification: NSNotification){
    println("Video finished playing")

    self.dismissViewControllerAnimated(false, completion: nil)
    NSNotificationCenter.defaultCenter().removeObserver(self)

    let reason =
    notification.userInfo![MPMoviePlayerPlaybackDidFinishReasonUserInfoKey]
        as NSNumber?

    if let theReason = reason{

        let reasonValue = MPMovieFinishReason(rawValue: theReason.integerValue)

        switch reasonValue!{
        case .PlaybackEnded:
            // The movie ended normally
            println("Playback Ended")
        case .PlaybackError:
            // An error happened and the movie ended
            println("Error happened")
        case .UserExited:
            // The user exited the player
            println("User exited")
        default:
            println("Another event happened")
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3685901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档