Adding specific touch event to UIButton iPhone - iphone

I am trying to add a touch to UIButton.
I want it to be when I click on button, until I release the finger, it won't click on it.
I Have played with many touch events, Touch down, Touch up inside etc but none is working like that. This is a very common touch event. How can I add such a thing in iPhone UIButton?

Touch up inside will only execute when you remove your finger from the button
Touch down event will work as soon as you touch the button.
Sample Project:
https://www.dropbox.com/s/hm82u553ktyszbd/ST-16385963.zip

Touch up inside is the event you should use here. If it doesn't work, that means you haven't implemented it correctly.

Could you post your code? It sounds like you want the Touch Up Inside functionality of not firing until the finger is raised.

Related

Why is touch-up-inside event not triggered on a uibutton when another button is being pressed?

I am working on a musical instrument type app. It uses a keyboard like set of UIButtons to trigger playing a musical note when touchDown occurs. The note stops playing based on touchUpInside or touchUpOutside events.
Everything works as expected except when attempting to play multiple notes. The touchDown events work, but touchUpInside event is not sent when a button is released as expected when another button continues to be touched. The touchUpInside is sent to all the buttons when all the buttons are released.
It appears to buffer other touch events until the button being held is released. If a button is released and another pressed, the touchDown and touchUpInside events are not sent to that button until all the other buttons are released. Then the touchUpInside events are sent to the first buttons and the subsequent events are triggered.
This flow has been traced through the code for the IBActions for the events. I have enabled multitouch. I have tried allowing multiple gesture recognizers. Nothing seems to affect this behavior.
There is no real code to share as the buttons and events were built using Interface Builder - Storyboard.
Is there something holding up the processing of events pending the release of previous touch events?
Any suggestions would be appreciated? I have searched for other similar questions but could not find this issue.
Thank you!
As your piano keys, use custom views, not UIButtons. You can probably most easily track the kind of touches you want to detect by attaching a UILongPressGestureRecognizer to each view. Or, at a lower level, you could simply detect touch events directly.

Slide to and from UIButtons and make them respond

I am creating a semi-piano app in Objective-C for iPhone; it's in fact a diffrent layout MIDI Controller, but I'm still working on the design.
I created all of the "keys" with UIButtons, and I want to be able to slide to them or from them to other UIButtons.
I read all the similar questions before, but I couldn't make it to work with touchesMoved,
Because it only worked from the view if I didn't drag the finger from a UIButton.
Thanks in advance, code will be appreciated!
Are your buttons created in IB? The default event when connecting buttons in IB is "touch up inside", which means the action is fired when the user ends a touch (lifts the finger) inside the button. A piano key or similar would be more appropriate to fire on the "touch down inside" (for the initial press) and the "touch drag enter" (for when a finger that is already on the screen moves into the button).
Since you are doing it programmatically, you can add targets to the buttons as described here:
http://developer.apple.com/library/ios/documentation/uikit/reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instm/UIControl/addTarget:action:forControlEvents:
Just include the events you want in the mask.

ccTouchesMoved and selector:#selector(ButtonTapped:)

Ill try and keep this as simple as possible.
I have a guy which you drag around the screen
I have a shoot button which fires bullets
To drag the guy around the screen im using ccTouchesMoved, basically get the users finger movement and set the guy to that place. Done.
I have a button which is a CCMenuItemImage and if it is tapped then is called a selector to run a method. The method simply fires some bullets. Done.
Now my problem is i cant have these two things work at the same time. I would like the player to be able to drag around the guy and shoot at the same time. Im assuming the button is not being tapped becuase the user is touching and dragging around the player.
How can i fix this? Still be able to drag around with one finger and press the shoot button with the other and they both work together?
You might want to implement your fire button using a sprite. You can handle ccTouchesBegan and ccTouchesEnded to check for a press within the bounds of your button, to swap it with a pressed state (on begin) or to implement the fire action (on end).
In your ccTouchesMoved handler, you can iterate over the set of touches and determine if the touch that moved is the one over the button, or the touch that should change the character position.

how to stop user use more than two fingers to touch

in my app, I want users only use one finger to touch the ipad, it means, when you touch the screen, others touches won't respond events......
any helps?
try disabling multitouch throug IB or through code.
keep a track of count of touch, and then implement it accordingly.

Cocoa Touch - Drag onto button to trigger event

Hey all, just wondering what the best way to add this capability was.
I want to be able to press the button normally by doing touchDownInside, but I also want to be able to slide my finger from one button to the next and have the next one trigger.
How can I do that?
Ex:
(-) -> (-)
^Buttons^
You can implement touchesEnded method and check if the touch point is within any of your button's frames..