增加类别,在输入第二个字时

前段时间总监有个需求让我实现,就是可伸缩的UIButton

在本类存在:#import "UIScrollView+UITouch.h"

[self.view addGestureRecognizer:tapGestureRecognizer];

@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];

}

@end

ios UIScrollView不能响应TouchesBegin:的事件的解决办法

1:@property MyScrollView *scrollView;

2:给MyScrollView,增加类别:MyScrollView+Touch

3:在类别里实现下面三个方法:

@implementation MyScrollView (Touch)

  • (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];
    }
    @end

4:- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self hiddenkeyBoard];
}

UIScrollView不能响应TouchesBegin:的事件的解决办法 1 :@property MyScrollView *scrollView; 2:给MyScrollView,增加类别:MyScrollView+Touch 3:在类别里实...

最后要实现的效果大概就是这样。

unrecognized

}

注:我类目头文件只在某个界面的.m文件引入,也变成全局了,别的界面也都影响了。这个令人费解。如果大家对这个有好的解决方法,欢迎留言,或者QQ我,QQ:348031375  备注:简书。

图片 1

//    [super touchesEnded:touches withEvent:event];

iOS 手写输入法奔溃,一种方法是常见的新建一个view监听点击手势,隐藏键盘,然后这个view最后加入到self.view要整屏宽高,

之前一个版本线上项目突然大规模出现这个报错信息,[UIKBBlurredKeyView candidateList]这个错误google一下基本都是说scrollview重写了触摸事件和手写输入法冲突。

- touchesBegan:touches withEvent:(UIEvent *)event{ [super touchesBegan:touches withEvent:event]; self.highlighted = YES; if (![objc_getAssociatedObject(self, DragEnableKey) boolValue]) { return; } begincenter=self.superview.center; UITouch *touch = [touches anyObject]; beginPoint = [touch locationInView:self.superview];}

//    [super touchesMoved:touches withEvent:event];

- (void)keyboardHide:(UITapGestureRecognizer *)sender

也欢迎更多iOSer来交流

*- touchesBegan:(NSSet)touches withEvent:(UIEvent)event;*

*- touchesMoved:(NSSet)touches withEvent:(UIEvent)event;*

*-touchesEnded:(NSSet)touches withEvent:(UIEvent)event;*

//

另外一种就是,判断一下是否是uiscrollview,看了网上一个帖子觉得挺好

UIScrollView 上如果有UITextField的话,结束编辑(退出键盘)直接用touchesBegan方法无效,需要再给UIScrollView加一个分类,重写几个方法。

网上已经有很多前辈给了相关代码是这样的(阅前提示:这样是有问题的!):

- (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];

}

这样会有一个严重问题,就是使用手写输入法输入中文会导致崩溃(虽然使用手写输入法的人不多,但也不能无视他们)。被坑死,问题是百度出来尼玛80~90%全是这种解决方法。坑死人!

有一些前辈对于“UIScrollView点击空白处退出键盘”就提出了另一种解决方法:加一层view,给view一个点击事件,退出键盘。

但是我的项目中已经被前一种方法坑了,已经有用户反映手写崩溃,换第二种方法的话很麻烦,需要修改之后重新提交审核,不能及时解决,我需要及时的用JSPatch线上打补丁解决。调试了很久,我发现手写键盘在调用UIScrollView的这个分类的方法时,self的类型是UIKBCandidateCollectionView,一种系统没有暴露出来的类型,应该是UIScrollView的一个子类,所以解决办法就呼之欲出了,直接上代码。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

if (![self isMemberOfClass:[UIScrollView class]]) {

} else {

[[self nextResponder] touchesBegan:touches withEvent:event];

if ([super respondsToSelector:@selector(touchesBegan:withEvent:)]) {

[super touchesBegan:touches withEvent:event];

}

}

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if (![self isMemberOfClass:[UIScrollView class]]) {

} else {

[[self nextResponder] touchesMoved:touches withEvent:event];

if ([super respondsToSelector:@selector(touchesBegan:withEvent:)]) {

[super touchesMoved:touches withEvent:event];

}

}

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

if (![self isMemberOfClass:[UIScrollView class]]) {

} else {

[[self nextResponder] touchesEnded:touches withEvent:event];

if ([super respondsToSelector:@selector(touchesBegan:withEvent:)]) {

[super touchesEnded:touches withEvent:event];

}

}

}

作者:vincent涵

链接:

來源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

name:NSInvalidArgumentException

reason:-[UIKBBlurredKeyView candidateList]: unrecognized selector sent to instance 0x100dae340

比如:

//- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

//设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。

我确实重写了这几个方法,为了解决scrollview加在uiview上,uiview的点击事件的。但是网上说的几个办法并不行,有人提出重写viewController的touch方法,用ismemberOf区分下scroll,但是我由于用的界面太多,所以没有测试。目前只能暂时先去掉这个类目(毕竟用户数量虽少,闪退是很重的)。

本文由必威发布于必威-编程,转载请注明出处:增加类别,在输入第二个字时

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。