关闭

ios开发--键盘隐藏

128人阅读 评论(0) 收藏 举报

-(void)setupKeyBoard

{

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

    tapGr.cancelsTouchesInView = NO;

    [self.view addGestureRecognizer:tapGr];

}

 

-(void)viewTapped:(UITapGestureRecognizer*)tapGr

{

    [_iphoneTextField resignFirstResponder];

    [_passwordText resignFirstResponder];

}

 

或者

//设置键盘隐藏

<UIGestureRecognizerDelegate>

-(void)setupKeyBoard

{

UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvent:)];

singleFingerOne.numberOfTouchesRequired = 1; //手指数

singleFingerOne.numberOfTapsRequired = 1; //tap次数

singleFingerOne.delegate= self;

[self.view addGestureRecognizer:singleFingerOne];

}

-(void)handleSingleFingerEvent:(UITapGestureRecognizer*)tap

{

self.loginTableView.contentSize = CGSizeMake(0,0);

[self.view endEditing:YES];

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:5448次
    • 积分:133
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:18篇
    • 译文:0篇
    • 评论:0条