美文网首页
scrollView添加touch

scrollView添加touch

作者: 井空烀地瓜 | 来源:发表于2016-07-01 13:16 被阅读42次

在项目中 点击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];

}

相关文章

网友评论

      本文标题:scrollView添加touch

      本文链接:https://www.haomeiwen.com/subject/ekwfjttx.html