简体   繁体   中英

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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