刚刚将项目从iOS5升级到iOS7。出于某种原因,我无法理解视频现在在segue工作之前播放了两次
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"LogoVC viewDidAppear");
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"start_sting_logo_resolve" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
// no moviecontrolls
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.scalingMode = MPMovieScalingModeAspectFill;
moviePlayerController.view.backgroundColor = [UIColor whiteColor];
[moviePlayerController play];
}
#pragma mark - Video methods
- (void)moviePlaybackComplete:(NSNotification *)notification
{
NSLog(@"moviePlaybackComplete");
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
[self performSegueWithIdentifier:@"segueToScroller" sender:self];
NSLog(@"preformed performSegueWithIdentifier");
}
视图根据日志加载两次
2014-07-01 14:25:17.872 Appname[1620:60b] LogoVC viewDidAppear
2014-07-01 14:25:31.745 Appname[1620:60b] moviePlaybackComplete
2014-07-01 14:25:31.766 Appname[1620:60b] LogoVC viewDidAppear
2014-07-01 14:25:31.965 Appname[1620:60b] preformed performSegueWithIdentifier
2014-07-01 14:25:44.089 Appname[1620:60b] moviePlaybackComplete
2014-07-01 14:25:44.124 Appname[1620:60b] preformed performSegueWithIdentifier
2014-07-01 14:25:44.190 Appname[1620:60b] ScrollerVC viewDidLoad
视频文件是本地的。
MPMoviePlayerPlaybackDidFinishNotification正在触发,但是视频控制器似乎重新加载而不是执行segue,只有第二次调用MPMoviePlayerPlaybackDidFinishNotification才会调用segue。
如果这会产生任何差异,那就是自定义segue
#import "JBCustomSegue.h"
@implementation JBCustomSegue
- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
int orient = [UIApplication sharedApplication].statusBarOrientation;
if (orient==3){
// Orient for Landscape Right 4
[UIView transitionWithView:src.navigationController.view duration:0.3
options:UIViewAnimationOptionTransitionCurlUp
animations:^{[src.navigationController pushViewController:dst animated:NO];} completion:NULL];
} else if (orient==4) {
// Orient for Landscape Left 3
[UIView transitionWithView:src.navigationController.view duration:0.3
options:UIViewAnimationOptionTransitionCurlDown
animations:^{[src.navigationController pushViewController:dst animated:NO];} completion:NULL];
} else {
// Orient for Landscape Right 4
[UIView transitionWithView:src.navigationController.view duration:0.3
options:UIViewAnimationOptionTransitionCurlDown
animations:^{[src.navigationController pushViewController:dst animated:NO];} completion:NULL];
}
}
事情是,每iOS7都没有发生这种情况
答案 0 :(得分:0)
罪魁祸首似乎是_moviePlayerController.fullscreen = YES;
我使用[_moviePlayerController.view setFrame: CGRectMake(0, 0, 1024, 768)];
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"start_sting_logo_resolve" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayerController];
// no moviecontrolls
_moviePlayerController.controlStyle = MPMovieControlStyleNone;
[_moviePlayerController.view setFrame: CGRectMake(0, 0, 1024, 768)];
[self.view addSubview:_moviePlayerController.view];
//_moviePlayerController.fullscreen = YES;
_moviePlayerController.scalingMode = MPMovieScalingModeAspectFill;
_moviePlayerController.view.backgroundColor = [UIColor clearColor];
[_moviePlayerController play];