Signature Panel - iphone

My requirements are I need a panel where user can make signature. The concept is like when user touches the screen and move the pointer, it should be marked with continuous line.
Please gimme some idea how to implement this??

Subclass UIView and override the various UIResponder methods dealing with touch. Especially pay attention to touchesMoved:withEvent: - this is the method where you can get data about the previous/current points of the touch, and potentially add them to a set of points the touch has moved through. You can also override drawRect: in your custom UIView to draw a curve through all the points the touch has passed.
More info:
UIResponder reference
UIView reference

Related

Making multiple moving images respond to taps

In the app, I have several images (same shape and size, different colors) that move on the perimeter of a circle, kinda like cursors acting as compass needles. I want to be able to tap each of these and then display a message based on which one is tapped, but am not sure what kind of approach would be good for this. Right now I'm trying making them in to UIButtons, but it's giving me a lot of hassle. Is there a way to do this with a UITapGestureRecognizer? I doubt it's possible to have one of those on the screen, but have it keep track of 6 different moving areas and let other tap events through, and I don't think adding 6 different recognizers is a good idea, so I'm just wondering if anyone has suggestions on how to go about this. I'm using Core Graphics.
The best method to achieve this effect would probably be to subclass a UIButton (or even UIControl if you'd like) that has the method that overrides touch. For example if you were to subclass UIControl you could override the method below to detect touches and do what you wish with them:
-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
Then whatever you want it to look like could be done in the drawRect: method by overriding that (and uncommenting it). Same goes for subclassing anything and tracking touches within the subclass: UIButton, UIImageView, UIControl, etc.

A question about CALayer and UIView

The object is to implement a semi-transparent layer which would slid out to collect user response when needed. The semi-transparent layer would have some icons on it for the user to choose from. Currently I am using a CALayer object which seems ok and it has some build in animation behavior.
But the problem is CALayer does not response to any touch events at all. Now I am thinking that I should be using a UIView instead. UIView inherits from UIResponder, so its objects are naturally capable of responding to users' events.
It's a decision between UIView and CALayer. For the CALayer, I have done quite a bit of work on it and it looks quite ok except about the touch response that has to be added. Or should I use a UIView as subview instead (since it has build-in touch respond) ?
Hope that somebody knowledgable on this could help ...
In order to respond to user interaction, the best way is to use a UIView. You could probably get it to work without one, but I wouldn't recommend it.
As for integrating your existing layer with the UIView, I'd create a subclass of UIView and override its +layerClass method to return the Class of your custom CALayer. Alternatively, if you're not using a custom CALayer subclass (and there generally isn't a real need to create your own), you can do your custom drawing inside the UIView's -drawLayer:inContext: method.

A user-movable dot on a map view?

What would be the best way to place a dot (a custom png) on an MKMapView, and allow the user to move the dot around the map. Additionally, when the finger is released, the map should center on the dot...
Are the any techniques which could make this possible?
I think you should check out the MKOverlayView class, as this should help you out with drawing the custom png.
You could perhaps subclass this class and override the instance methods – touchesMoved:withEvent:, – touchesEnded:withEvent and – touchesCancelled:withEvent: to handle the user input?

Determining which view touch was in for all touches

I want to determine which view touches occurred in for the entire application, for the purpose of logging touches so that I can go through the logs later and determine what the user did. I know I could subclass UIView and override touchesBegan/Ended to log those, but I am using many instances of UIButton, UISlider, etc in Interface Builder so that wouldn't work unless I also subclassed those classes.
For determining the time since last touch (for an idle screen timeout method) I already have UIApplication subclasses and sendEvent: overridden. The only way I can see to do what I want is to iterate through the main window's subviews, calling touchesForView: on the UIEvent passed into sendEvent:, but I was wondering if there was a cleaner way to tell which view was touched (whether it's through the sendEvent: method or not). Thanks!
See if this will do what you want: Observing pinch multi-touch gestures in a UITableView

Do CALayers block Touch Events in underlying views?

I have an application with a view containing several subviews. The subviews did not implement any touchesbegins logic. The Superview implemented all touchesbegins logic and manipulated each subview respectively if it was touched (determined by hit testing).
I have since been converting my subviews to layers. My problem now is that if I touch a layer, the hosting view of the superlayer never gets the touchesbegins method called. However if I touch the background, the touchesbegin method fires.
I understood from documentation that layers cannot handle events, if this is so why would it block events to the hosting view?
Thanks for any help, can't get my head around this.
-Corey
I found the problem... I was releasing the sublayers I was creating using [CALayer layer]. Since I didn't have control of them, I shouldn't have been managing them.
CALayers should not block touch events. Is your userInteractionEnabled flag set in the hosting view (sounds like it is, if you're getting SOME touches)? Is it inside a UIScrollView, which may be doing its own touch-handling.
What class is your touchesBegan method in?
I was having a similiar problem because my touchesBegan method was in a UIView subclass.
After moving the method to a UIViewController subclass, my problem was fixed.
Try doing that.