How to Identify a touch/tap on an iPhone screen - iphone

I need to know which method is used to identify tap/mouse click.I
know
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {}
which are triggerd when cursor moved.
But I want to do following things-
I have an image.
When i will click it, similar two image will be created.And so on
Can anyone help????Advanced thanx for your reply.

The tap events are handled not by the touches method callbacks in UIView, but as targets-actions in UIControl. UIControl is a subclass of UIView, and adds abstractions for taps, drags and other common user actions, so that you do not need to implement the logic yourself.
To add a action for the user tapping a control simply do this:
[myControl addTarget:self
action:#selector(didSelectFoo:)
forEvents:UIControlEventTouchUpInside];
This is usable both if you subclass UIControl yourself, or if you use any of the provided controls such as UIButton, UITextField, UILabel, etc.

Related

why are touches (set) are passed instead of a touch in touchesBegan?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
why is 'touches' not just 'touch' being passed for touchesBegan/Moved/Ended?
What's the meaning of them?
That's because user may do a multiple taps (quickly) in which case you'll receive a set of multiple NSTouch objects.
A demonstration of this is the zooming effect when you double tap on a scroll (or image) view.
Because you can receive multiple touches, but they are disabled by default. In order to receive multiple touch events you must set the multipleTouchEnabled property of the corresponding view instance to YES and touch with 2 or more fingers.

How to freeze UI when start up?

When the app is launched, I want to freeze UI for a second or so to get a precondition service (for example - location service) initialized. Is there a way to do that?
Just place a transparent UIView on top of the entire screen and have it intercept all touch events.
To intercept touch events, simply subclass a UIView and override
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;
Usually inside that method you'd call super on it, but in this case you would just return YES:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
return YES;
}
If you'd like to be really fancy you can add a synthesized property to the UIView subclass called shouldInterceptTouches and do something like this:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
return shouldInterceptTouches ? YES : [super pointInside:point withEvent:event];
}
Also remember to make sure that your transparent view is above the other views.
Side-note: Apple's Human Interface Guidelines don't like it when you do stuff like that. A user will be confused and disappointed if your app is not responsive and it may cause them to quit the app if they think it's frozen. You're better off displaying some sort of UIActivityIndicatorView and disabling only the buttons absolutely necessary. Apple likes it when you do stuff like that in the background and allow the user to do other things, just in case it takes a while or fails.
You could use a Modal View or disable all components until the location service has finished.
This is the responsibility of the application not the OS or the frameworks.

How to catch event of pressing TableViewCell?

I have question for you ...
I have UITableView and I want to catch event when user press the cell in order to change the color of label that I insert into UITableViewCell. The moment when user touch the cell.
tableView:willSelectRowAtIndexPath:
tableView:didSelectRowAtIndexPath:
functions didn't help me ...
Who have any suggestion ? Thanks a lot for help !!!
If you want to change the color of a UILabel inside a UITableViewCell when it's selected, you don't have to do any sort of event catching. You just have to change the highlightedTextColor property of the UILabel. The default is usually white.
Subclass the UITableViewCell and override the UIResponder with these:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
Then you will have 2 separated events when press and when release.
Did you set the delegate of the tableView?
Did your class conform to the UITableViewDelegate protocol?
Confirm With UITableViewDelegate protocol and implement the methods which you mention,
Do'nt forget to set the delegate property of your UITableView.
myTableView.delegate = self;
Have you looked at UILongPressGestureRecognizer? See: http://developer.apple.com/library/ios/#documentation/uikit/reference/UILongPressGestureRecognizer_Class/Reference/Reference.html%23//apple_ref/occ/cl/UILongPressGestureRecognizer

Responding to touch in other classes

I'm building an iPhone app on top of the OpenGL template for the iPhone. I was about to add user interaction to the app when I noticed that it won't respond to touches in a few of my classes.
Currently, the GameAppDelegate calls my EAGLView class' startAnimation method, which eventually calls my ES1Renderer class' render method, which then finally calls my Scene render method. I know it's a bit of a mess at this point, but I'll clean it up eventually.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event is only called and checked for in my EAGLView class. I don't know what I'm missing in the other classes (most importantly my Scene class) that will automatically check to see if I have that method and implement it.
Judging just from the naming scheme, it sounds like Scene is not a UIView. The touch event method is called on whatever UIView is touched -- in this case, your EAGLView. If you'd like the Scene class to handle it, you can just call the method directly:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[myScene touchesBegan:touches withEvent:event];
}

How to determine click location coordinates in iphone app view class

i'm trying to make a connect four iphone app. I have made my own custom UIView class, which is where the game is played. However, I am trying to use the touchesMoved, touchesEnded, etc. methods to retrieve data based on where the user clicked (so i know which column they are trying to put a piece into). How can i get this information from the viewController class to my UIview class?
I would just use - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event and potentially override - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event to ignore touches in views that I may have overlaid. It does depend on your view hierarchy really.