我在视图中添加了一个子视图。我在触摸时找到它,当它是动画触摸事件是找到子视图.. 这是代码......
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch self]) {
NSLog(@"View Touched");
}
if ([[touch view] isKindOfClass:[Baloon class]]) {
NSLog(@"Baloon Touched");
}
}
答案 0 :(得分:0)
你应该在你的Baloon Class中实现“touchesBegan”方法,并在“touchesMove”方法中设置新的位置到Baloon!
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
switch ([allTouches count]) {
case 1: {
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
[self setCenter:[touch locationInView:self.superview]];
}
break;
default:
break;
}
}