Two buttons inside the cell accepts the touch even when both the buttons touched simultaneously - ios

For one of the cells inside tableview I have added two buttons. When I touch those buttons separately they performing their operations correctly. But the problem now is when I touch both the buttons simultaneously both accepts the touch and triggers their own target method. I don't want this to happen. Only one button should accept the touch at a time.

I located solution for this by setting exclusiveTouch of the button to TRUE.

Use Exclusive Touch property:
self.button1.exclusiveTouch = true

Related

Two separate UIButtons sharing same press... can't press two at one time

I have a view set up as a game controller for an UIImageView on my screen. I have two directional arrows left/right, and an A and B button.
When the user holds a directional (touch down) it moves the player, and on the touch Up method it stops.
However, while holding a directional UIButton, the other UIButtons will not function until you release the touch Up on the directional, thus delaying the tap.
Also, say if you held the A button down and simply tap a directional once, the A button will register the directional button being touched down instead of A, even though A will be in its highlighted state.
I have checked the connections for everything, they are all separate UIButton instances with only those actions linked.
It seems that a touchUp method is being passed to another UIButton instance making two presses at the same time impossible. I have not had issues with this before.
Any help would be appreciated thank you.
Check that multipleTouchEnabled is true for parent views:
multipleTouchEnabled
A Boolean value that indicates whether the receiver handles
multi-touch events.
And that exclusiveTouch is false for buttons:
exclusiveTouch
A Boolean value that indicates whether the receiver handles touch
events exclusively.

Click on two buttons at the same time, if one covers the other one

What I want to do is just as the tiltle says. The reason is , I am not able to custome the view of the below button, so I plan to put another button on this button which can be customed by myself. And when I touch the upper one, the event of the belown one will be triggered.
Let's say there are two UIButtons A & B.
In the touch event (touchupinside) of A add the following code:
[buttonObjectB sendActionsForControlEvents: UIControlEventTouchUpInside];
This will trigger second button's touch event as you desire.

UIPanGestureRecognizer passes the event down to a button underneath

I have a side panel that has a UIImageView to which I attached a UIPanGestureRecognizer so that you could push/pull the sidebar.
It works well.
Thing is that I have some buttons that happen to sometimes occur underneath that sidebar. If I pull it and a button is underneath, the button would fire simultaneously with the Pan.
I am not sure what the problem is, so I find it hard to solve.
Why does my UIImageView pass the UIPanGestureRecognizer event on down the chain?
Problem solved with delegation.
I disable the events on toucheBegan if a BOOL called isPanning is set to YES for all buttons.
The protocol defines only one function:
-(void)setPanning:(BOOL)isPanning;
in the touchedBegan I check to see if the value is YES, if so I don't fire that event.
I wished it would be simpler.

Using a UIView as a button

I'm trying to use a UIView I've created in Storyboard as a button. I assumed it would be possible to use a UIButton, setting the type to custom. However I was unable to add subviews to a custom UIButton in Storyboard.
As such I've just spent the last hour reinventing the wheel by making my own custom gesture recoginizers to reimplement button functionality.
Surely this isn't the best way of doing it though, so my question - to more experienced iOS developers than myself - is what is the best way to make a custom button?
To be clear it needs to:
Use the UIView I've created as it's hittable area.
Be able to show a
different state depending on whether is currently highlighted or not
(i.e. touch down).
Perform some action when actually tapped.
Thank you for your help.
You can use a UIButton, set the type to custom, and then programmatically add your subviews...
Change your UIView into a UIControl in the storyboard. Then use the method [controlViewName addTarget:self action:#selector(*click handler method*) forControlEvents:UIControlEventTouchDown];. click handler method is a placeholder for the method name of your handler. Use this method except change out the UIControlEventTouchDown for UIControlEventTouchInside and UIControlEventTouchDragExit to call a method when the user finishes their click and drags their finger out of the view respectively. I used this for something I'm working on now and it works great.
In Touch down you will want to: highlight all subviews
In Touch up inside you will want to: unhighlight all subviews and perform segue or do whatever the button is supposed to do
In Touch Drag Exit you will want to: unhighlight all subviews
See second answer by LiCheng in this similiar SO post.
Subclass UIControl instead. You can add subviews to it and it can respond to actions
Why are you implementing your own GestureRecognizer? I recommend using the UIView so you can add subviews in the interface builder and adding a UITapGestureRecognizer. You can even do this graphically since you don't care about IOS4 support.

Pass touch events to one of multiple options

I've created a board of UIImageViews, that are held within a single object as an NSArray. all the imageviews are displayed as subviews of the 'board'(the object that holds the array). What I would like to do is when I touch any of the individual squares of the board (the imageviews) that the one that is touched is the one that picks up the event. Currently the board picks up all the touch events. passing the touches automatically to nextResponder doesn't work, since there isn't a single nextResponder, but many, with a single one being the correct one.
By default, UIImageView overrides the value of the userInteractionEnabled property to NO (see http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html#//apple_ref/occ/instp/UIImageView/userInteractionEnabled). This is what is causing your UIImageViews to not receive touch events, and so they are accepted by the board superview.
To make it so your UIImageViews receive touch events, just set the userInteractionEnabled property to YES.

Resources