Iphone 如何更改MPMoviePlayServiceWController的UIModalTransitionStyle
当我使用mpmovieplayervicewcontroller时,除了默认的向上滑动动画之外,我似乎无法将modalTransitionStyle更改为任何其他内容 还有其他人能让这个工作吗Iphone 如何更改MPMoviePlayServiceWController的UIModalTransitionStyle,iphone,ios4,mpmovieplayercontroller,Iphone,Ios4,Mpmovieplayercontroller,当我使用mpmovieplayervicewcontroller时,除了默认的向上滑动动画之外,我似乎无法将modalTransitionStyle更改为任何其他内容 还有其他人能让这个工作吗 MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoURL]]; theMoviePlayer.m
MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoURL]];
theMoviePlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // doesn't work
[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];
感谢您观看
这里的代码似乎还将呈现
mpmovieplayervicewcontroller
实例的视图控制器的modalTransitionStyle
设置为相同的值。这行得通吗?我发现用CrossDisolve模式动画启动“MPMoviePlayServiceController”实例的方法是在导航控制器内启动电影播放器,如下所示:
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];
以及收听MPMoviePlayerPlaybackDidFinishNotification通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
并在视频结束后将其关闭:
-(void)movieDidFinish:(NSNotification *)notification {
[self dismissViewControllerAnimated:YES completion:nil];
}
埃卡里翁的回答非常有帮助——这是一个快速的版本,希望能为人们节省一些时间
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")
}
}
}
谢谢,沙吉。事实上,它并没有完全起作用——但秘密就在你指给我的密码里。如果您使用新的[self-PresentMoviePlayeServiceController激活:移动层];然后,将忽略过渡样式。但是,如果使用标准的[self-presentModalViewController:animated:],则它适用于电影的过渡,但在电影结束时仍使用默认幻灯片动画。古怪的哦,这个链接有一些非常好的技巧,可以让3.1/2和4.0兼容的电影播放。干杯