IOS UITextView实现自动隐藏键盘

来源:互联网 发布:zcash linux挖矿教程 编辑:程序博客网 时间:2024/05/13 10:13

不讲原理。只讲操作。

三 步 :

设置  Text input traits ---》Return key 为DONE

         去掉auto-enable Return key 选中状态。

创建一个类为:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #b80fa2}span.s1 {color: #b80fa2}


@interface BoardReturn : NSObject <UITextFieldDelegate> {


}

@end

 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3c0f81}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #b80fa2}span.s1 {color: #b80fa2}span.s2 {color: #6f32a9}span.s3 {color: #000000}span.Apple-tab-span {white-space:pre}

@implementation BoardReturn


- (BOOL)textFieldShouldReturn:(UITextField *)textField {

[textField resignFirstResponder];

return NO;

}


@end


在你的Controller中加入此类

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #cf231d}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #b80fa2}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008700}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3c0f81}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #508187}span.s1 {color: #77482b}span.s2 {color: #b80fa2}span.s3 {color: #000000}span.s4 {color: #508187}span.s5 {color: #6f32a9}span.s6 {color: #3c0f81}span.Apple-tab-span {white-space:pre}

#import "Controller.h"

#import "BoardReturn.h"


@implementation Controller


 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

 - (void)viewDidLoad {

         //view上的UIinputfiled 对应的 IBoutlet.

myText.clearButtonMode=UITextFieldViewModeWhileEditing;

myText.delegate=[[[BoardReturn alloc] init] autorelease]; 

    [super viewDidLoad];

 }



原创粉丝点击