一、隐藏键盘。
1、首先设置xib中得UIView的Custom class为UIControl
2、设置关系事件,将xib中得UIView拖到.h区中
connection设为action;ID类型点击事件为Touch Up Inside
3、在.m编写隐藏代码:
- (IBAction)按钮名称:(id)sender {
[self.view endEditing:YES];
}
备注:如果通过view创建的可以直接 [self.view endEditing:YES];
二、隐藏PickerView控件。
- (void)viewDidLoad
{
[super viewDidLoad];
//----------------------------------(
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
//设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。
tapGestureRecognizer.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tapGestureRecognizer];
//-这个方法也可以用于是点击空白处移除键盘或pickerview控件------------------------------)
}
-(void)keyboardHide:(UITapGestureRecognizer *)tap{
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.3;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromBottom;
[locateView setAlpha:0.0f];
[locateView.layer addAnimation:animation forKey:@"TSLocateView"];
[locateView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.3];
self.Nolocation.userInteractionEnabled =YES;
}