YYKit icon indicating copy to clipboard operation
YYKit copied to clipboard

YYTextView on ScrollView

Open WeeTom opened this issue 9 years ago • 13 comments

目前如果吧YYTextView放到ScrollView上,进行选择操作,会带动scrollView滚动,导致选择失败, 不知道你有没有注意到这点,有好的解决方案吗

WeeTom avatar Mar 14 '16 09:03 WeeTom

UIScrollView 嵌套 UIScrollView,默认的交互就是这样。 与 YYTextView 无关。

ibireme avatar Mar 14 '16 09:03 ibireme

OK,但是UITextView不会有这个问题,也许有些特殊的步骤吗

WeeTom avatar Mar 14 '16 09:03 WeeTom

也许有吧。。 这个以后有时间可以看一下。

ibireme avatar Mar 14 '16 10:03 ibireme

好,谢谢!

Yaoyuan [email protected]于2016年3月14日 周一18:21写道:

也许有吧。。 这个以后有时间可以看一下。

— Reply to this email directly or view it on GitHub https://github.com/ibireme/YYKit/issues/132#issuecomment-196241929.

WeeTom avatar Mar 14 '16 10:03 WeeTom

y神,如果 yytextview 添加了yyhighlight 在滑动到highlight的时候 会有卡顿,感觉滑动不流畅

yupliang avatar Apr 02 '16 09:04 yupliang

YYTextView 内部是直接绘制成一张图片的,所以当文本显示出来之后,应该不会再出现卡顿了。这个可以在 Instruments 里调试一下看看是何处占用了资源。

ibireme avatar Apr 02 '16 12:04 ibireme

在绘制成图片的时候确实滑动流畅,这边遇到的问题是,从高亮处开始滑动,会再调用两遍绘制方法 YYTextLayout.m 中的 - (void)drawInContext:(CGContextRef)context size:(CGSize)size point:(CGPoint)point view:(UIView *)view layer:(CALayer *)layer debug:(YYTextDebugOption *)debug cancel:(BOOL (^)(void))cancel 2. 并且在YYKit demo 中也遇到了这样的问题,即在YYTextEditExample.m中把原先的文本It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the season of light, it was the season of darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us. We were all going direct to heaven, we were all going direct the other way.\n这是最好的时代,这是最坏的时代;这是智慧的时代,这是愚蠢的时代;这是信仰的时期,这是怀疑的时期;这是光明的季节,这是黑p暗的季节;这是希望之春,这是失望之冬;人们面前有着各样事物,人们面前一无所有;人们正在直登天堂,人们正在直下地狱。 多复制几遍,然后添加一个highlight即可重现。

yupliang avatar Apr 04 '16 06:04 yupliang

当触摸高亮时,会重新排版和绘制以显示高亮样式,松手后,会重新绘制原来未高亮的样式。YYTextView 没有异步绘制,所以可能与这个有关。如果不需要文本编辑,那可以改用 YYLabel 并开启异步绘制模式。

ibireme avatar Apr 04 '16 11:04 ibireme

没有用yylabel测试过,YYlabel没有选择一段文字的功能呀.如果在yylabel的基础上添加选择文字功能怎么做呢

yupliang avatar Apr 04 '16 13:04 yupliang

YYLabel 只有文字显示功能、YYTextView 有显示、选择、编辑的功能,这些都和 UIKit 表现一样。如果这也觉得卡那就没办法了。。

ibireme avatar Apr 04 '16 13:04 ibireme

YYlabel用的异步绘制,很不错的。只是需要一个选择部分文字以添加高亮的功能……

yupliang avatar Apr 04 '16 13:04 yupliang

这个滑动的问题 你解决了吗 ,我也遇到了 @WeeTom

mws100 avatar Feb 04 '17 10:02 mws100

找到原因了,手势操作是在touch系列方法里的,被外层scrollview手势识别后,取消了touch系列的回调,我加了两个代理设置外层scrollview的scrollEnable,就可以了如下:

@protocol YYTextViewDelegate <NSObject, UIScrollViewDelegate> - (void)textViewTouchesMovedWhenTrackingGrabber; - (void)textViewTouchesEndedWhenTrackingGrabber; @end

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { ... if (_state.trackingGrabber) { if ([self.delegate respondsToSelector:@selector(textViewTouchesMovedWhenTrackingGrabber)]) { [self.delegate textViewTouchesMovedWhenTrackingGrabber]; } .... } ... }

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { ... if (_state.trackingGrabber) { if ([self.delegate respondsToSelector:@selector(textViewTouchesEndedWhenTrackingGrabber)]) { [self.delegate textViewTouchesEndedWhenTrackingGrabber]; } ... } ... }

q1367880593 avatar Dec 14 '20 11:12 q1367880593