Swipe Gestures and drawing user touches error - iphone

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!

Related

showing touches on iOS device like in the simulator

For the purposes of making app demos and presentations, I would like to draw circles corresponding to touches, just like in the iOS simulator, but on the device itself.
Ideally, this would be orthogonal to other code. Perhaps a UIView which draws the circles and forwards the events, but event forwarding seems to require the other views be aware:
http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MultitouchEvents/MultitouchEvents.html#//apple_ref/doc/uid/TP40009541-CH3-SW17
Is there a clean way of doing this?
(I can't use the simulator for demos because my app uses gestures, MIDI, and OpenGL)
thanks!
There is a framework call fingertips which is available through cocoapods.
http://cocoapods.org/?q=on%3Aios%20fingertips
This will do what you are asking.
I don't think there's a clean way of doing this. However, this is what I would try:
Use method swizzling to hook up to all your views by swizzling the methods
- touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
for the UIView class. In addition, you may also need to swizzle some methods of UIGestureRecognizer subclasses, since they may prevent the methods listed above from being called. This way you can do your own thing (e.g. draw the touch points on the screen), and also let the views handle the touches as before.

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.

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.

UIAutomation pinch simulation

I'm trying to build a testing script for my iPhone application. Inside this test, I'm trying to simulate a pinch action.
I read on the official Apple reference that is possible to call the pinchOpenFromToForDuration function of UIATarget, but the simulator responds to this action how a double tap action (I'm sure because with double tap i perform another action in my code).
I can't understand how I can solve this problem, is possible to use any other trick to reach the same result?
Thank's
Marco
The odd behavior you are experiencing very well could be the coordinates you are using for the pinchOpenFromTo operation.
If the coordinates translate to something that does not "pinch" - like a WebView - then you usually get the click or tap result you mention. That has been my experience, anyway.
Use UIGestureRecognizer class for the zooming functionality. It would be easy for you to handle.
If you are in need of Pinch gesture use UIPinchGestureRecognizer class and delegate to handle that.
For Tap you may use UITapGestureRecognizer class and delegate methods….