在项目中 点击textfield 要把页面向上提 这样就需要在底层添加scrollView来改变偏移量 但是有个问题 点击空白处回收键盘
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event
{
[textField1 resignFirstResponder];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
textField1 = textField;
}
这句代码 百试百灵的 居然不好使了 在这里出个解决办法 建个类目
//.h
#import@interface UIScrollView (UITouch)
@end
//.m
#import "UIScrollView+UITouch.h"
@implementation UIScrollView (UITouch)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesMoved:touches withEvent:event];
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesEnded:touches withEvent:event];
[super touchesEnded:touches withEvent:event];
}