简体   繁体   English

触发将UIButton触摸内部的动作拖到外部,然后松开手指

[英]Trigger an action on UIButton touch inside dragged outside and then release finger

I need a UIButton to perform a specific action when the user touches inside the button, the without releasing the touch drag outside the button and then release the finger. 当用户在按钮内部进行触摸时,我需要一个UIButton来执行特定的操作,而无需释放按钮外部的触摸拖动,然后释放手指。 I don't want the action to be performed if he touches inside the button and then drags out and without raising the finger goes back into the button again and then release finger (which would effectively become a touch up inside, which is also not the sender I am looking for). 我不希望如果他触摸按钮内部然后将其拖出并且在不抬起手指的情况下执行该动作,然后再次放回按钮,然后松开手指(这实际上会变成触摸内部,这也不是我正在寻找的寄件者)。 Is there any sender type to do the particular action in the specified condition? 是否有任何发送者类型可以在指定条件下执行特定操作? I hope the doubt is clear enough. 我希望这个疑问已经足够清楚。 Please mention if you have doubt regarding what I asked. 如果您对我的要求有疑问,请提及。

UIControlEventTouchUpOutside对您不起作用吗?

[myButton addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpOutside];

you can do it as below 您可以按照以下步骤进行操作

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

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *aTouch = [touches anyObject];
    CGPoint point = [aTouch locationInView:self.view];

}

here what you need to do is that compare point (CGPoint) with your button's area and act accordingly 在这里,您需要做的是将比较点(CGPoint)与按钮的区域进行比较并采取相应的措施

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM