如何检测MPMoviePlayerController窗口上的触摸并仍然具有标准播放控制

时间:2010-03-22 12:18:14

标签: iphone objective-c mpmovieplayercontroller mpmovieplayer

我将MPMoviePlayerController设置为播放电影。我想检测电影上的触摸以显示几个按钮。我使用了代码:


 // The movie's window is the one that is active
        UIWindow* moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
        // Now we create an invisible control with the same size as the window
        UIControl* overlay = [[[UIControl alloc] initWithFrame:moviePlayerWindow.frame]autorelease];

    // We want to get notified whenever the overlay control is touched
    [overlay addTarget:self action:@selector(movieWindowTouched:) forControlEvents:UIControlEventTouchDown];

    // Add the overlay to the window's subviews
    [moviePlayerWindow addSubview:overlay];

然后回放控制器没有出现,我猜是因为播放器窗口没有触摸。我可以保留播放器控制器并仍然检测到触摸吗? 感谢

1 个答案:

答案 0 :(得分:1)

您必须创建自己的UIView的子类并将其添加为叠加层。

在方法-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event中,您可以在触摸屏幕时执行您想要执行的所有操作。

我在我的项目中完成了这项工作。我在Interface Builder中实现了VideoOverlay(UIView的子类)的设计。当你必须添加用户必须与之交互的其他元素时,它会容易得多。