使用UITextView作为子视图创建UIScrollView获取触摸事件 [英] Make a UIScrollView get touch events with a UITextView as a subview

查看:104
本文介绍了使用UITextView作为子视图创建UIScrollView获取触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含UITextView(不可编辑)的UIScrollView。
我无法让UIScrollView获取触摸事件,UITextView似乎得到它们并保留它们。知道怎么让UIScrollView获取触摸事件吗?

I have a UIScrollView that contains a UITextView (not editable). I can't make the UIScrollView gets the touch events, UITextView seems to get them and keep them . Any idea how to let UIScrollView gets the touch events?

我希望UITextView仍然可以垂直滚动(我的UIScrollView只能水平滚动)。

I want UITextView to still be scrollable vertically (my UIScrollView is scrollable only horizontally).

推荐答案

UITextView 子类中,执行以下操作:

In your UITextView subclass, do this:

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

如果你想要 UITextView 处理触摸,然后我相信你可以这样做:

If you want UITextView to handle the touches too, then I believe you can do this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.nextResponder touchesBegan:touches withEvent:event];
    [super touchesBegan:touches withEvent:event];
}

但这可能会导致非常奇怪的行为。

but it might result in really weird behavior.

这篇关于使用UITextView作为子视图创建UIScrollView获取触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆