Hola guys. I m experiencing a little problem with touch handling and UIResponder.
我的目标是管理一次触摸(移动)来与不同的视图交互。
我在UIImageView中添加了一个手势识别器,它会向我的customViewController发送一条简单的消息。它在点击的UIImageView上分配并显示一个自定义视图(子类化UIButton)。
我可以(不必释放最初的手指敲击)将触摸移动发送到我新分配的自定义按钮。
It seems that my UIImageView swallow my touch and so my new Button can t feel the finger movement. I tried to resign first responder but it seems having no effect.
我的自定义按钮工作得很好,但前提是我释放第一次点击,然后再次点击新的显示按钮。
Any suggests? Thank you in advance.
此处的某些代码:
在我的viewController中,我将一个长按手势识别器连接到我的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方法在circularMenu中手动处理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:我用touchMoved手动处理触摸,因为如果我使用addTarget:action:forControlEvents:在我的按钮(1、2、3和4)上,检测到touchEvent的按钮会吞下它,使其他按钮无法感觉到触摸在它们上面移动。