dragging and dropping a button in iphone - iphone

I need to drag and drop UIButtons(image) on bigger UIImageView. I want to implement following functionality -
While dragging if the button is inside UIImageView then only it should drop,else it should not drop
When touching down and dragging it should immediately create a new UIButton at original position.
After the UIButton is dropped it should not move from its new position.
Thanking in advance.

I'm not quite sure if this is what you're looking for but what you can do is start a timer on the touchDown action that will trigger a method that makes the button update to the current CGPoint touch location. Then add if statements to control whether it's inside an image or not. To make the button stop, use the touchUpInside method and invalidate the timer.

Related

Adding specific touch event to UIButton 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.

TouchDragEnter into a UIButton

Is it possible to TouchDown outside a uibutton and then dragInside another UIButton with the UIEventTouchDragEnter or something like that?
I need help with the code. I tried it with imageView but i would appreciate a solutions with buttons!
Thank you!
Franhu
The UITouchDownEvent event must happen inside the button for the button to track the touch. The UITouchDragEnter event means that the touch started inside the button (generating UITouchDownEvent), moved outside the button (generating UITouchDragExitEvent)' then moved back inside the button (generating UITouchDragEnterEvent).

Drag button with touch move

I am working on a custom controller. I want to create a slider, to choose between more options. The problem is that when I touch the button I want to it doesn't call my touchesBegan method. But if I press in any other part of my view, it works. How can I get my button to move?
Thanks.
The UIButton is capturing the touch events. if you try this
myButton.userInteractionEnabled = NO;
Then it will no longer consume the touch events but it will also no longer fire the onTouchUpInside event. In this case you process all of the touches in the super view and position the slider button accordingly.
It should drag just fine. This will work for any UIView.
touchesBegan will not work on a UIButton .. for that to work you will have to subclass UIButton and implement touchesBegan
refer this answer for more info https://stackoverflow.com/a/4863734/919545
Why don't you create a custom UIView and avoid using the UIButton class? It is simplier that subclassing UIButto or to set
myButton.userInteractionEnabled = NO;

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.

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