大家好。我在触摸处理和 UIResponder 方面遇到了一点问题。
我的目标是管理一次触摸(移动)以与不同的视图进行交互。
我向我的 UIImageView 添加了一个手势识别器,它向我的 customViewController 发送一条简单的消息。它在点击的 UIImageView 上分配并显示自定义视图(继承 UIButton)。
我将能够(无需释放初始手指点击)将触摸移动发送到我新分配的自定义按钮。
似乎我的 UIImageView 吞下了我的触摸,所以我的新 Button 感觉不到手指的移动。我试图辞去第一响应者的职务,但似乎没有效果。
我的自定义按钮工作得很好,但前提是我释放第一次点击,然后再次点击新的显示按钮。
有什么建议吗?先感谢您。
这里有一些代码:
在我的 viewController 中,我将一个 longPressGestureRecognizer 附加到我的 profileImageView 中,它在 profileImageView 周围绘制了一个圆形按钮。
-(void)showMenu:(UIGestureRecognizer*)gesture {
[profileImageView removeGestureRecognizer:gesture];
[profileImageView setUserInteractionEnabled:NO];
ConcentricRadius radius;
radius.externalRadius = 75;
radius.internalRadius = 45;
GTCircularButton *circularMenu = [[[GTCircularButton alloc] initWithImage:[UIImage imageNamed:@"radio.png"] highlightedImage:[UIImage imageNamed:@"radio_selected.png"] radius:radius] autorelease];
[circularMenu setTag:kCircularTagControllerCircularMenu];
[circularMenu setCenter:[profileImageView center]];
// Buttons' frames will be set up by the circularMenu
UIButton *button1 = [[[UIButton alloc] init] autorelease];
UIButton *button2 = [[[UIButton alloc] init] autorelease];
UIButton *button3 = [[[UIButton alloc] init] autorelease];
UIButton *button4 = [[[UIButton alloc] init] autorelease];
[circularMenu setButtons:[NSArray arrayWithObjects:button1, button2, button3, button4, nil]];
//[[self view] addSubview:circularMenu];
[[self view] insertSubview:circularMenu belowSubview:profileImageView];
}
现在我使用 touchMoved 方法手动处理 circleMenu 内的 touchEvent。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchLocation = [(UITouch*)[touches anyObject] locationInView:self];
for (UIView *aSubview in _roundButtons) {
if ([aSubview isKindOfClass:[UIButton class]]) {
UIButton *aButton = (UIButton*)aSubview;
CGPoint buttonTouchPointConverted = [aButton convertPoint:touchLocation toView:aButton];
if (CGRectContainsPoint([[aButton layer] frame], buttonTouchPointConverted)) {
[self rotateHighlightImage:aButton];
}
}
}
}
目标始终是处理手势识别器的结束并将触摸事件传递给创建的新实例,而无需将手指从屏幕上抬起。
有任何想法吗?
PD:如果我使用 addTarget:action:forControlEvents: 在我的按钮(1、2、3 和 4)上,我使用 touchMoved 手动处理触摸,检测到 touchEvent 的按钮会吞下它并使其他按钮无法感觉到触摸移动他们。