How to simulate touch event? - iphone

I want to be able to invoke touch events without user interactions.
Is this possible?

you could manually call touches begin and touches end.
I think there may be a better solution to whatever you are trying to do, This seems like a very unconventional thing to do.

Have a look at UIResponder's touchesBegan:withEvent: and touchesEnded:withEvent:

Related

On iOS, to find the ending swipe location, we need to use UIPanGestureRecognizer, so why not use touchesEnded?

It is said that a Swipe Gesture UISwipeGestureRecognizer cannot tell the ending location of the swipe (which is kind of strange), and that we need to use UIPanGestureRecognizer instead, as described in this question: UISwipeGestureRecognizer Swipe length
But using that method, isn't it the same if touchesBegan and touchesEnded is used instead? Is there a reason or advantage to use UIPanGestureRecognizer instead?
You can use either ... depends on your choice. It actually depends on your requirement and what you really want to do. If you want to use UITouch you can go ahead .
Also in the link you provided there is the last answer "You can only do it a standard way: remember the touch point of touchBegin and compare the point from touchEnd."
So touches is a lengthier method whereas using gestures makes your code look less .

Detecting a finger being held on an object

I am trying to have an image that when the user touches it, it wiggles and as soon as the user lifts their finger it stops.
Is there a gesture that I can use to detect when the finger is down, not just on the initial touch, or when the user moves there finger?
I have tried a LongPress gesture, but that does not get called the entire time the finger is on the view. Can anyone help me with the best way to active this. Right now i am doing it using touchesBegin, touchesMoved, touchesEnd, but i was wondering if there is a better way.
Any suggestions are greatly appreciated.
Thanks
EDIT
Based on the comments, I slightly misunderstood the original question, so I edit my answer to a different solution, which hopefully is a bit more clear (and answers the actual question - not the one that was in my head).
A LongPress gesture is continuous (where a tap gesture is not). That means, the recognizer callback will continue to be invoked until the gesture is complete - which does not happen until the "longpress" is released. So, the following should do what you want. NOTE: I think you want to "start shaking" a view when the long-press is recognized, then "stop shaking" the view when the fingers are released. I just pretended you have functions for that. Substitute appropriately.
- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
StartShakingView(gestureRecognizer.view);
} else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
StopShakingView(gestureRecognizer.view);
}
}
The Apple Touches sample includes code that demonstrate using both UIResponder and UIGestureRecognizer methods.
Either should work for what you're doing.
Simple answer - you could make the image a UIButton, and start the wiggle on TouchDown, and stop it on TouchUpInside or TouchUpOutside
It sounds like you want to subclass UIGestureRecognizer, which, as I recall, gets the touchesBegan:... and associated methods. Read the notes on subclassing in the UIGestureRecognizer reference. Or use a UIButton as SomaMan suggests.

Swipe Gestures and drawing user touches error

i have UISwipeGestureRecognizer that detects if the user has swiped. i also draw the users touches using the touches moved method found in the tutorial below.
http://www.ifans.com/forums/showthread.php?t=132024
My issue is the gesture seems to override my drawing. is it possible to do both or is there a better way of doing this?
Thanks
Dan
All of the touches methods get overridden when you invoke a gestureRecognizer. You can view it here in the explanation. It may be best to just write your own code to recognize a gesture if you need all of the touch events for drawing updates. If you still want to use a gestureRecognizer, you can use the locationInView: method to find the location of the touch, and then pass those points to your draw method.
I would also think about using OpenglES instead, as it isa bit easier, and you can do more things. There's a great sample project about it here. Hope that helps!

Recognising touch events in iPhone

If the user writes "t" on the particular touch area, the iPhone should recognise it and it should be displayed.
Where should the user write? Is there any specific area like UItextfield and how is it recoginised (letter written by the user)?
Apparently there is something that's called UITextField and you can access it's properties. But you should (TOTALLY) read through the developer.apple.com stuff first. There are also some nice videos on youtube and on apple that will help you get an entry.
Please! don't be lazy and learn about the basics! If you have any further questions about usage or something else: Use the Forum Search! Google it! Then ask your question!
You can subclass the UIVIew and create an new custom View.
Define the following methods:
touchesBegan:withEvent:
touchesMoved:withEvent:
touchesEnded:withEvent:
touchesCancelled:withEvent:
Each time user starts touching and ends the touch record the set of of points user has traveled and use these stored values in drawRect Method to draw lines between them.
Implement drawRect: method in your custom view and do the drawing of lines according to the users touch points.
You can also consider creating a gesture recognizer for this. This is the basic guide that can get you started.

Need a UIButton to tell me continuously whether or not it is touched

There's probably something really obvious I'm missing, but no matter how I trawl the documentation & the blogs, I can't find a way to make a button report whether or not it is being touched, regardless of whether the touch moves, etc. I have an up & down button, & I need to call the relevant method whenever there is a finger on it.
Many thanks,
Franklyn Weber
Add an action to the touch down event and you are being touched up until any of the touch up events are fired. If you need to be continuously called, use an NSTimer. Start the timer on touch down and then check to see if you are still down in the timer handler. If you are, do your thing and set another timer.