码迷,mamicode.com
首页 > 其他好文 > 详细

关闭键盘

时间:2015-01-22 21:40:55      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

1、点击固定的按钮关闭键盘

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [textField resignFirstResponder];

    return YES;

}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{

   if([text isEqualToString:@"\n"])

   {

       [textView resignFirstResponder];

       return YES;

   }

    return YES;

}

2、点击其他关闭键盘

- (void)viewDidLoad

{

    [super viewDidLoad];

    UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];

    tapGr.cancelsTouchesInView = NO;

    [self.view addGestureRecognizer:tapGr];

}

-(void)viewTapped:(UITapGestureRecognizer*)tapGr{

    [self.textField1 resignFirstResponder];

}

关闭键盘

标签:

原文地址:http://www.cnblogs.com/zhanggui/p/4242725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!