IOS keyboard First Response

Source: Internet
Author: User
Tags uicontrol

IOS keyboard First Response

. UIResonder inherits from the Control class for all controls (such as TextBox) in C. The inheritance relationship of the Control class is as follows: System. Object System. MarshalByRefObject System. ComponentModel. Component System. Windows. Forms. Control has a similar inheritance relationship for the UI class in iOS. For example, UITextField is inherited from UIControl; UIControl is inherited from UIView, UIView is inherited from UIResponder, and UIResponder is inherited from NSObject. For specific architecture, see: http://developer.apple.com/library/ios/#documentation/general/conceptual/Devpedia-CocoaApp/Responder.html
UIResponder is the class in the UIKit framework (Mac OS X Cocoa corresponds to the AppKit framework ). 2. The first response object will become the first response object in the application response object. What is the difference between the first response object and other response objects? There is no difference between common touch events. Even if I set a button as the first response object, when I click another button, it will still respond to other buttons without giving priority to the first response object. The difference between the first response object is that it is responsible for handling events unrelated to the location of the screen, such as shaking. In Apple's official document, the first response object is the object in the window, which the application considers to be the most suitable for event processing. A class can have only one class leader. Only one response object in the application can be the first response object. 3. Become and cancel the first response object. To be the first response object, you also need a View for self-Recommendation:-(BOOL) canBecomeFirstResponder {returnYES;} if this section is missing, even if you use [view becomeFirstResponder], you cannot make a view the first response object... Is it sweet? Well, that's not the reason. By default, most views only care about events associated with themselves, and (almost) always have the opportunity to handle these events. Taking UIButton as an example, when you click a UIB utton object, the object will receive the specified action message regardless of the view of the current first response object. Is the first response object thankless... Therefore, you can only specify a UIResponder as the first response object. (I don't know what the design is based on... Security ?) In the first response object, different objects may have some special performances. For example, when UITextField is used, a keyboard is called up. The first response object may also be dismissed. Send a resignFirstResponder to persuade you to leave. 4. The task of the first response object just said that the first response object can handle shaking. Let's take a look at an example:-(void) motionBegan :( UIEventSubtype) motion withEvent :( UIEvent *) event {if (motion = UIEventSubtypeMotionShake) {NSLog (@ "Device is Ning inning to shake"); [selfsetCircleColor: [UIColorredColor]; [selfsetNeedsDisplay];} triggers certain actions when shaking starts. 5. retrieving the current first response object comes from this discussion: http://stackoverflow.com/questions/1823317/get-the-current-firs t-responder-without-using-a-private-api the guy who asks questions uses the following method to get UIView * firstResponder = [keyWindow into mselector: @ selector (firstResponder)]; the result was called back by Apple, indicating that a non-public API was used... So this guy had to use recursion: implementationUIView (FindFirstResponder)-(UIView *) findFirstResponder {if (self. isFirstResponder) {return self;} for (UIView * subView in self. subviews) {UIView * firstResponder = [subView findFirstResponder]; if (firstResponder! = Nil) {return firstResponder;} return nil;} @ end

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.