【问题标题】:Make a UIScrollView get touch events with a UITextView as a subview使用 UITextView 作为子视图使 UIScrollView 获取触摸事件
【发布时间】:2009-03-25 14:00:15
【问题描述】:

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

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

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

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

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

    如果您也希望UITextView 处理触摸,那么我相信您可以这样做:

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

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

    【讨论】:

    • 我想在 UITextView 中保持滚动功能。这不会避免 UITextView 可滚动吗?我更新了我的问题以提供更多信息。
    • 会的。所以你希望两个视图都接收到触摸?
    • 效果很好!并且没有奇怪的行为, UIScrollView 和 UITextView 的行为符合预期。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2013-07-26
    • 2011-07-10
    • 2011-07-11
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多