Keyboard hiding in IOS uimodalpresentationformsheet style

Source: Internet
Author: User

1. In the view under Uimodalpresentationformsheet (IPad device, without a uinavigationcontroller), if you use the

[Inputview Resignfirstresponder];

Keyboard can not be put up, you need to use the following ways:

A:

@try

{

Class Uikeyboardimpl = nsclassfromstring (@ "Uikeyboardimpl");

ID activeinstance = [uikeyboardimpl performselector: @selector (activeinstance)];

[Activeinstance performselector: @selector (Dismisskeyboard)];

}

@catch (NSException *exception)

{

NSLog (@ "Exception:%@", Exception);

}

The method above is not approved because it uses Apple's private API.

B. The view under Uimodalpresentationformsheet cannot be resignfirstresponder because after entering this mode, the system returns the values in the following method to Yes:

-(BOOL) disablesautomatickeyboarddismissal

{

return YES;

}//Disablesautomatickeyboarddismissal, this method is in Uiviewcontroller.

After you change the return value to No, you can hide the keyboard normally using the Resignfirstresponsder method, but this method still fails in Uinavigationcontroller, which is supplemented by the following.

2. If you display the Uimodalpresentationformsheet view in Uinavigationcontroller, then rewrite it in Uinavigationcontroller Rootviewcontroller

The Disablesautomatickeyboarddismissal method will also not be able to enable the Resignfirstresponder method effect because the displayed view is Uinavigationcontroller, Should be in the Uinavigationcontroller.

To override the Disablesautomatickeyboarddismissal method. This is done by extending the way to the Uinavigationcontroller to override this method:

#import<UIKit/UIKit.h>@interfaceUinavigationcontroller (Uinavigationcontroller_keyboarddismiss)-(BOOL) disablesautomatickeyboarddismissal;@end#import "Uinavigationcontroller+uinavigationcontroller_keyboarddismiss.h"@implementationUinavigationcontroller (Uinavigationcontroller_keyboarddismiss)-(BOOL) disablesautomatickeyboarddismissal{returnNO;}//Disablesautomatickeyboarddismissal@end

After rewriting the Disablesautomatickeyboarddismissal method by Uinavigationcontroller category, the problem of Resignfirstresponder method invalidation can be solved.

Reference: http://stackoverflow.com/questions/3372333/ Ipad-keyboard-will-not-dismiss-if-modal-view-controller-presentation-style-is-ui

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.