[IOS SDK] - touchesBegan与特定对象?

时间:2010-12-17 17:53:44

标签: xcode ios4 touchesbegan nsset touchesmoved

当我触摸屏幕上的任何地方触摸触发事件时触发。但我无法管理如何像UIImageView一样触摸特定对象?

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

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

 CGPoint location = [touch locationInView: touch.view];

 imageView.center = location;

}

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

 [self touchesBegan:touches withEvent:event];

}

1 个答案:

答案 0 :(得分:13)

好的,找到了解决方案,这里是代码:

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

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

    if ([touch view] == imageView) {

        CGPoint location = [touch locationInView: self.view];

        imageView.center = location;

    }

}