MPMoviePlayerViewController上的UIGestureRecognizer

问题描述:

我想知道你们中的任何人是否遇到过类似的问题,当然碰巧找到了正确的或不正确的(但工作中)的解决方案/解决方法。MPMoviePlayerViewController上的UIGestureRecognizer

我正在使用MPMoviePlayerViewController,我试图将一个Swipe-Gesture识别器添加到MPMoviePlayerViewControllers视图中。

moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:currentChannel.StreamURI]];
[moviePlayerViewController.movi​​ePlayer setControlStyle:MPMovieControlStyleNone];
moviePlayerViewController.movi​​ePlayer.movi​​eSourceType = MPMovieSourceTypeStreaming;
moviePlayerViewController.movi​​ePlayer.shouldAutoplay = YES;
[moviePlayerViewController.movi​​ePlayer setScalingMode:MPMovieScalingModeAspectFit];我们可以使用UISwipeGestureRecognizer * swipeGestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(previousChannel)];
swipeGestureRight.direction = UISwipeGestureRecognizerDirectionRight;
[myMoviePlayerViewController.view addGestureRecognizer:swipeGestureRight];
[self.view addSubview:moviePlayerViewController.view];

无论如何,它“有点作品”,但是当我通过在正在运行的电影播放器​​实例(无论是在模拟器还是在设备上)上执行手势来测试整个事件时,应用程序崩溃,控制台状态

** -[CFRunLoopTimer invalidate]: message sent to deallocated instance 0xf074bb0 

没有任何人对此主题有想法吗?

看来,iOS正在释放您的MPMoviePlayerViewController对象,然后再发送消息给它。我会建议把你的实例类的成员,然后实例的属性吧,比如:

@property (nonatomic, retain) MPMoviePlayerViewController *moviePlayerViewController; 

...与相应的@synthesize声明你的类的实现文件一起。当分配你的对象,你应该然后做:

self.moviePlayerController = [[[MPMoviePlayerViewController alloc] initWithContentURL:@"yourUrl"] autorelease]; 

最后,通过在dealloc方法将其设置为nil释放对象。