I have cocos2d application which contains the mapview in it , i want to handle the touch,zoom,and other ui event but i am no able to do that cause i have to extend the class with the uiviewcontroller which is not possible cause i have already extended with the CCLayer so can i have some source code to do this
Thanking you.
Rohit
the mapview handles all touch events and when the events happens inside the mapview they are not sent to the controller by default.
A work around for that is to use gesture recognizers in your mapview
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer
Related
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!
I setup a network call in appdelegator class to get some infomation back, and I want to show it in the frist UIView. How to pass the data to that UIView?
I mean the UIView may be visible or may be destroyed and replaced by other one, if it was visible, how to pass that value to it?
is there any publish/subscribe events mechanism in iphone sdk?
You can do this a few different ways, including using key-value observing or NSNotifications.
The basic idea is that when you load your UIView, you want to register it as an observer of a key path/posted notification of the app delegate. When you deallocate your view, you should unregister it as an observer.
That's a very basic question.
How can I catch for example the "touchesBegan" event of a UIWindow instance? So that whenever the user is touching the window a method I set is called?
Thank you!
F.
For iOS 3.2+: Create a gesture recognizer and add it to the view you are interested in.
Posting the tutorial that got my head around Gesture Recognisers:
http://www.conceitedcode.com/2010/06/implementing-gesture-recognizers/
F.
Can i create custom touch events for iPhone?? will the device support for creating my own touch event handling ?
Take a look at the UIResponder class:
http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html
You will probably want to implement the touchesBegan:withEvent:, touchesEnded:withEvent: and touchesCancelled:withEvent: methods. These will all be called with an NSSet of UITouches that you can do whatever you want with.
As of the 3.2 SDK there are UIGestureRecognizer classess. They do not play well with the older UIResponder calls, but if you can do 3.2 only they are easier to get going.
There are a number of handy subclasses, such as UIRotationGestureRecognizer for handling rotation.
If you are extending Apple classes like UIScrollView you must use gesture recognizers with 3.2 and later because when a gesture recognizer cancels it will cancel your UIResponder call tracking as well. If you are handling all the gesture tracking this is not an issue.
I am developing an iPhone application with multiviews (Nav controller), but i like to receive an event if user touches in any view of the view. I understand it can be done by subclassing application delegate? If that's true how can i do it? My requirement is, i like to receive an event as soon as user touches any where in any view within my application.
Thanks for your help and time.
Your reference to subclassing UIApplication will work. Read down through the comments and it covers a somewhat quirky IMO way to implement it (by having the AppDelegate be a subclass of UIApplication). Myself, I would create a separate class to be the UIApplication subclass, rather than having the app delegate do both jobs, but I see the merit of either way.
That said, this is a very large and unusual stick and may suggest a design failure. What problem are you solving with this?
A way to do it is to use a Singleton class (which acts as an observer/mediator), which the application is an example of, in which you have viewControllers subscribe to when they are intersted in the touch events of a certain view. When the touch occurs the Singleton class is informed of the event as a result it informs all subscribers to the event of the event.
Here is an example
#interface MyEventClass
{
-(void)TouchEventDidOccur;
-(void)subscribeToTouchEvent:(id)delegate selector(selector):sel
}
Above is the singleton class
now this is an example of what the view touchesBegan method might look like
-(void)touchesBegan...
{
[[MyEventClass sharedInstance] TouchEventDidOccur];
}
and how one would subscribe to the event
[[MyEventClass sharedInstance] subscribeToTouchEvent:self selector:#selector(receiveTouchEvent:)]
hope this helps
What's wrong with using notifications? If you have disconnected classes across your application, it's trivial to have them listen for a particular notification, then have your views or view controllers post that notification when a touch event happens. All of the observers will take action on the notification.