Wednesday, December 11, 2013

[Share] non-touch input area (background) makes UITextField (UISearchBar) method keyboard disappears

The soft keyboard appears on iOS, I hope clicking non-keyboard part, hide the keyboard, the keyboard disappear even if the methods discussed.

The soft keyboard appears on iOS, I hope clicking non-keyboard part, hide the keyboard, the keyboard disappear even if the methods discussed.

The first method: adding a button, the corresponding touch down event, hide the keyboard. In this way, too cottage. To add a button corresponding to an event so not worth it.

The second method: Add Tap event on the background image, click on the appropriate treatment. In this way, a good way to replace the button, but without the background image on UI, this method has returned to the ranks of the first method of the cottage.

[Plain] view plaincopy

/ / Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (Void) viewDidLoad
{
[Super viewDidLoad];

/ / Add background images
with processing timeUIImageView * backView = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
backView.image = [UIImage imageNamed: @ "small3.png"];

backView.userInteractionEnabled = YES;
UITapGestureRecognizer * singleTouch = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (dismissKeyboard :)];
[BackView addGestureRecognizer: singleTouch];

backView.tag = 110;
[Self.view addSubview: backView];

/ / Add uitextfield
text = [[UITextField alloc] initWithFrame: CGRectMake (30, 150, 250, 31)];
/ / [Text setBackgroundColor: [UIColor grayColor]];
text.borderStyle = UITextBorderStyleRoundedRect;
text.placeholder = @ "";
[Self.view addSubview: text];
/ / Add the Back button

UIButton * button = [UIButton buttonWithType: UIButtonTypeRoundedRect];
button.frame = CGRectMake (125, 40, 75, 35);
[Button addTarget: self action: @ selector (done :) forControlEvents: UIControlEventTouchUpInside];
/ / [Button setBackgroundColor: [UIColor grayColor]];
[Button setTitle: @ "return" forState: UIControlStateNormal];

[Self.view addSubview: button];
}

- (Void) dismissKeyboard: (id) sender {
[Text resignFirstResponder];
}


The third method: In the xib file, modify the objects properties xib file, the default is to view property, we can modify the UIControl property, which is xib file corresponding touch down event. In this way, the disadvantage is that there is no xib on the tragedy. But supposedly should be able to dynamically set, No Method, friends who know it, let me know next.

Detailed Reference: http://blog.csdn.net/ugg/article/details/7246164 < / a>
Reply:
I talk about treatment methods:
After the soft keyboard pops up, create a translucent cover View other locations in addition to the text box, click on the View when hide the keyboard.

There is a touch of penetration in the bottom of the View plus hidden keyboard function, upper Touch, events are mapped to the underlying View, and call functions.
This depends on the specific circumstances, to choose the right solution ideas.
Reply:
Learned, thanks to LZ and 1L
Reply:
cited a floor ybh37 reply:
talk about the way I handled:
After the soft keyboard pops up, create a translucent cover View other locations in addition to the text box, click on the View when hide the keyboard.

There is a touch of penetration in the bottom of the View plus hidden keyboard function, upper Touch, events are mapped to the underlying View, and call functions.
This depends on the specific circumstances, to choose the right solution ideas.


Brother, ask, how to cover the view, among other places in the text, thought a moment and could not think of
Reply:
You can refer to the method I mentioned
Reply:
Learning to be a good idea ....

No comments:

Post a Comment