- (void)viewDidLoad {
[super viewDidLoad];
[self setUpForDismissKeyboard];
}
#pragma mark - 回收任何空白区域键盘事件
- (void)setUpForDismissKeyboard {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
UITapGestureRecognizer *singleTapGR =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tapAnywhereToDismissKeyboard:)];
NSOperationQueue *mainQuene =[NSOperationQueue mainQueue];
[nc addObserverForName:UIKeyboardWillShowNotification
object:nil
queue:mainQuene
usingBlock:^(NSNotification *note){
[self.view addGestureRecognizer:singleTapGR];
}];
[nc addObserverForName:UIKeyboardWillHideNotification
object:nil
queue:mainQuene
usingBlock:^(NSNotification *note){
[self.view removeGestureRecognizer:singleTapGR];
}];
}
- (void)tapAnywhereToDismissKeyboard:(UIGestureRecognizer *)gestureRecognizer {
//此method会将self.view里所有的subview的first responder都resign掉
[self.view endEditing:YES];
}
#pragma mark - TextView 代理方法
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[self.workLogTextView resignFirstResponder];
return NO;
}
return YES;
}
#pragma mark 键盘遮挡
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
if (self.userInfo.isPhone4) {
CGFloat offset_y = 0.f;
if (textView.tag == CALL_CONTENT_TEXTFIRLD) {
offset_y = 100.f;
}
CGPoint point = self.BackScrollView.contentOffset;
point = CGPointMake(point.x, offset_y);
[UIView animateWithDuration:0.25 animations:^{
self.BackScrollView.contentOffset = point;
}];
}
return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
if (self.userInfo.isPhone4) {
CGFloat offset_y = 0.f;
if (textView.tag == CALL_CONTENT_TEXTFIRLD) {
offset_y = 100.f;
}
CGPoint point = self.BackScrollView.contentOffset;
point = CGPointMake(point.x, 0);
[UIView animateWithDuration:0.25 animations:^{
self.BackScrollView.contentOffset = point;
}];
}
return YES;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有