How to determine click location coordinates in iphone app view class - iphone

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.

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.

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];
}

MkMapView setRegion animation prevents touch events on Annotation Views

We have a MKmapView with a bunch of Image Annotation where each Image annotation responds to touch
by overriding these methods of AnnotationView subclass:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
Our map region is updated using
[MkMapView setRegion:animated:]
whenever the new location is received and is far enough from the old location to make a difference.
What I noticed is that if we set animated flag to YES the touches on our annotation are rarely detected(probably due to the fact that main thread is busy animating between two map regions.
When we set animated flag to NO, everything is fine, but map transition may(or may not) become jerky.
The question I have is whether this is an expected behavior of animated flag of [MkMapView setRegion:animated] function or whether there is a workaround for this issue.
Thanks in advance
Typically, the mapview being animated has its userInteractionEnabled property set to no during the animation. If you need to change this behavior, you should subclass the view and override the appropriate methods.
Alternatively, you could place a transparent view over the mapview for the duration of the animation to capture specific types of actions, such as respond to a double-tap to stop the change in region.

How to Identify a touch/tap on an iPhone screen

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.