Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UIButton Touch Drag Enter not working as expected?

I'm trying to create a button which will trigger an action when the user's touch is brought anywhere into the button (whether they touch down inside, or drag from outside to inside the button). Essentially, I need to create a way to trigger the action whenever a finger is inside of the button.

"Touch drag enter" combined with "touch down inside" sounds like it would do the job, but it seems to be working differently than what I need.

Also, I'd prefer if it can be done in storyboard rather than hard code (like touchesBegan/moved), but if there is no other way that's okay.

like image 224
stealthysnacks Avatar asked May 15 '13 03:05

stealthysnacks


2 Answers

Touch drag enter will only gets called, when u start the touch inside the control and drag it outside the bounds of the control and then drag it back inside the control, without leaving the touch. So you need to subclass your button and achieve the required functionality.

like image 172
Prasad Devadiga Avatar answered Oct 18 '22 02:10

Prasad Devadiga


Either you will have to bind all the events one by one with the method you are intending to invoke on button press from IB.

OR

You can try register your button for UIControlEventAllTouchEvents inside your code. Here is an example that might be helpful

[_btnRoundRect addTarget:self action:@selector(btnPressedAction) forControlEvents:UIControlEventAllTouchEvents];


- (void)btnPressedAction{
    NSLog(@"Bttn pressed");
}
like image 42
Deepesh Gairola Avatar answered Oct 18 '22 03:10

Deepesh Gairola