Home > DeveloperSection > Articles > Uses of UIResponder in Objective-C

Uses of UIResponder in Objective-C


iPhone iPhone  Ios  Objective C 
Ratings:
0 Comment(s)
 768  View(s)
Rate this:

Uses of UIResponder in Objective-C

UIResponder is a sub-class of NSObject class and it has many sub-classes, some of them are UIApplication, UIView, UIWindow, UIViewController. UIResponder class was came with iOS 2.0. It has very important role in iPhone, iPad app development. iOS apps recognize combinations of touches and responds to them, such as zooming in/out on contents, pinching gesture and scrolling through content in response to a flicking gesture. Some gestures are so common that they are built in to UIKit, like: UIControl subclasses such as UIButton and UISlider. Instances of these classes are sometime referred to as responder objects.


There are two general kinds of events:
* Touch Events
* Motion Events

Touch Events: this type of events occurs whenever any type of touch on device screen happens. like UIButton and UISlider classes having specific gestures like: tap for a button and drag for a slider. They send an action message to a target object whenever touch occurs. It works when we attach a gesture recognizer to a view, entire view acts like a control, they respond whenever we specify gesture on device view.
Important Touch Event methods:
touchesBegan:(NSSet *)setName withEvent:(UIEvent *)eventName;
- it tells the receiver when one or more fingers touch down in a view or window.

touchesMoved:(NSSet *)setName withEvent:(UIEvent *)eventName;
- it sent to the receiver when a system event(such as a log-memory warning) cancels a touch event.

touchesEnded:(NSSet *)setName withEvent:(UIEvent *)eventName;
- it tells the receiver when one or more fingers are raised from a view or window.

touchesCancelled:(NSSet *)setName withEvent:(UIEvent *)eventName;
- it tells the receiver when one or more fingers associated with an event move within a view or window.

All of these methods parameters are associate with their events, they also handles multi-touch gestures events.

Motion Events: this type of events occurs whenever we shake iPhone or iPad devices. motion events introduces in iOS 3.0, specifically the motion of shaking the device.
Its important Motion Event methods:
motionBegan:(UIEventSubtype*)subType withEvent:(UIEvent*)eventName;
- it tells the receiver that motion event has begun.

motionEnded:(UIEventSubtype*)subType withEvent:(UIEvent*)eventName;
- it tells the receiver that motion event has been cancelled.

motionCancelled:(UIEventSubtype*)subType withEvent:(UIEvent*)eventName;
- it tells the receiver that motion event has ended

In iOS 3.0 adds an additional method- canPerformAction:withSender: method, it allows responders to validate commands in the user interface.
In iOS 4.0, UIResponder adds an other method for Remote Events- remoteControlReceivedWithEvent: method, it handles remoteControl related events.


Don't want to miss updates? Please click the below button!

Follow MindStick