如何在UIScrollView中开始启用触摸? [英] How to enable touch began in UIScrollView?

查看:50
本文介绍了如何在UIScrollView中开始启用触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIScrollview,当我尝试捕获UIscrollview中的触摸事件时没有响应.我应该如何实现?我正在使用UILable来显示文本.

Am using UIScrollview, when i am trying to capture touch event in UIscrollview is not responding. how should i achieve it? i am using UILable for showing the text.

推荐答案

是的,我也遇到了同样的问题.但最终我得到了补救.解决方案是,您将必须创建一个从UIScrollview继承的类,如下所示:

Yes I was also facing the same problem.But finally I got remedy on it. Solution is that you will have to create a class inherited from UIScrollview as follows:

#import <Foundation/Foundation.h>
@interface CustomScrollView : UIScrollView 
{

}

@end

并按如下所示在其实现文件中覆盖touches方法:

And override the touches method in its implementation file as follows:

#import "CustomScrollView.h"


@implementation CustomScrollView

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

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    if(!self.dragging){
        [self.nextResponder touchesMoved:touches withEvent:event];
    }
}

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

@end

您将必须在所需文件中导入此类,并使用其对象而不是UIScrollview的对象.现在,您可以看到该控件可以触及您在其中添加了scrollview的类中的touchs方法.

You will have to import this class in the required file and use its object instead of UIScrollview"s object. Now you can see that control reaches to touches methods in the class in which you have added scrollview whenever you touch on it.

谢谢.

这篇关于如何在UIScrollView中开始启用触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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