在屏幕上获取所有触摸

时间:2013-01-31 04:48:14

标签: ios ios6 c4

我遇到了一个小问题。我想在屏幕上接收所有触摸,并为每个触发产生一个新视频。问题是,一旦放置视频,它就会拦截触摸点。我试着在locationInView中使用各种值,但到目前为止没有任何运气。我在寻找合适的地方吗?

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    CGPoint pointOnScreen = [[touches anyObject] locationInView:self.view];

    C4Movie *player = [C4Movie movieNamed:@"inception.mov"];
    player.shouldAutoplay = YES;
    player.loops = YES;
    player.center = pointOnScreen;
    [self.canvas addMovie:player];

 }
 @end

2 个答案:

答案 0 :(得分:3)

尝试将每个视频屏幕的userInteractionEnabled属性(假设它保存在某种UIView中)设置为NO - 这样,触摸事件将通过它并继续由处理程序接收。

答案 1 :(得分:3)

是的,你正在寻找合适的地方,克里斯对用户互动是正确的。你应该试试:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint pointOnScreen = [[touches anyObject] locationInView:self.view];
    C4Movie *player = [C4Movie movieNamed:@"inception.mov"];
    player.shouldAutoplay = YES;
    player.loops = YES;
    player.center = pointOnScreen;
    player.userInteractionEnabled = NO;
    [self.canvas addMovie:player];
}

但是,您将遇到添加视频的问题。 不幸的是,iOS /硬件只允许您同时运行4个视频管道,因此您可以快速点击

如果您想在触摸并拖动手指时向屏幕添加内容,则还可以在以下方法中执行上述代码:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    //work your magic here
}