2010-09-10 33 views
1

HI。我试图移动一个UIImageView对象与UITouch和有问题的代码我如何实现UITouch只检测我的UIImageView对象?使用UITouch检测特定对象

** imageA它在我的UIImageView

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

     UITouch *toucheA = [[event allTouches] anyObject]; 

    if ([toucheA view] == imageA) { 
     CGPoint location = [toucheA locationInView:self]; 
     imageA.center = location;  

    } 
} 

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

    [self touchesBegan:touches withEvent:event]; 
    CGPoint postion = imageA.center; 
    imageA.center = postion; 
    postion.y = 230; 
    imageA.center = postion; 

} 

但不工作!

回答

1

我想你可以通过继承自定义UIImageView并在自定义视图中接收你想要的触摸事件。

通常,最顶端的视图将接收触摸事件。如果视图处理触摸事件并且不将该事件传递给另一个视图,则其后的其他视图不可能接收到任何触摸事件。如果视图不能处理触摸事件,它将通过调用super的方法来传递。