动画完成iOS后播放视频

时间:2012-09-13 00:36:57

标签: ios animation uiview mpmovieplayercontroller

嗯..我有一个简单的动画,可以左右滑动2个图像视图..当它完成时,我想播放视频但是使用我现有的代码(下图),动画永远不会发生,视频开始播放。我该如何解决这个问题?感谢..

NSString *movpath = [[NSBundle mainBundle] pathForResource:@"testvideo" ofType:@"m4v"];
    mpviewController = [[MPMoviePlayerViewController alloc]
                        initWithContentURL:[NSURL fileURLWithPath:movpath]];
    [mainView addSubview:mpviewController.view];



    [UIView animateWithDuration:0.5 animations:^{
        leftView.frame = CGRectOffset(leftView.frame, 160, 0);
        rightView.frame = CGRectOffset(rightView.frame, -160, 0);
    }completion:(void (^)(BOOL)) ^{

        MPMoviePlayerController *mp = [mpviewController moviePlayer];

        [mp prepareToPlay];
        [mp setFullscreen:YES animated:YES];
        mp.controlStyle = MPMovieControlStyleNone;

        [[mpviewController moviePlayer] play];

    }
     ];

1 个答案:

答案 0 :(得分:0)

动画的完成块看起来不对。试试这个:

 [UIView animateWithDuration:0.5 animations:^{
        leftView.frame = CGRectOffset(leftView.frame, 160, 0);
        rightView.frame = CGRectOffset(rightView.frame, -160, 0);
    } completion:^(BOOL finished){

        MPMoviePlayerController *mp = [mpviewController moviePlayer];

        [mp prepareToPlay];
        [mp setFullscreen:YES animated:YES];
        mp.controlStyle = MPMovieControlStyleNone;

        [[mpviewController moviePlayer] play];

    }];