【问题标题】:Have problems in the touches触摸有问题
【发布时间】:2013-10-15 07:44:55
【问题描述】:

我有一个带有 UIScrollView 的 UIView,我想捕捉事件的触摸,但我不能。 不涉及以下任何方法。有什么问题?

- (void) touchesEnded: (NSSet *) toca withEvent: (UIEvent *) evento
{
     NSLog (@ "touchesEnded");

}
- (void) touchesBegan: (NSSet *) toca withEvent: (UIEvent *) evento
{

     NSLog (@ "touchesBegan");

}
- (Void) touchesMoved: (NSSet *) toca withEvent: (UIEvent *) evento
{
     NSLog (@ "touchesMoved");
}

标题##

谢谢

【问题讨论】:

  • 澄清一下,你有一个UIView 和一个UIScrollView 作为子视图添加,你正在尝试接触UIView?不是滚动视图,对吗?
  • 我需要接触 UIViews 或 UIScrollView。尝试在 UIScrollView 中捕获触摸时遇到问题?如何让触摸传递给 UIView?
  • 在你的 UIView.m 中实现这些方法
  • 请检查我是否理解正确......你在 UIScrollView 中有 UIViews,你需要捕获 UIViews 触摸事件吗?
  • 添加了 xib 的打印屏幕

标签: ios objective-c uiview uiviewcontroller uitouch


【解决方案1】:

您需要使用 UIGestureRecognizer。 您可以直接将其添加到您的 viewController 中:

UITapGestureRecognizer *tap =
              [[UITapGestureRecognizer alloc] initWithTarget:myView action:@selector(yourSelector:)];
          [myView addGestureRecognizer:tapp];

否则你可以直接用界面巨石添加它:

添加手势识别器后,您可以像普通插座一样使用它。

【讨论】:

    【解决方案2】:

    正如 Benny Dalby 所说,有一种方法可以制作 UIScrollView 的子类并可以执行您的触摸事件

    在您的滚动视图子类实现文件中,您可以执行这些功能

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    [super touchesBegan:touches withEvent:event];
    
    
    }
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
    [super touchesMoved:touches withEvent:event];
    
    
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
    [super touchesEnded:touches withEvent:event];
    
    
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    {
    [super touchesCancelled:touches withEvent:event];
    }
    

    【讨论】:

    • 必须缺少某些东西,因为这些方法似乎无法显示。我用谷歌搜索了一些教程的方法 - (Void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event - (Void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event - (Void) touchesEnded: ( NSSet *) touches withEvent: (UIEvent *) event - (Void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) 事件并实现但没有成功。
    • 我有一些项目使用和管理的方法正确实施,这次我没有得到。我的任何故障我不是维修我使用Max_Power89的形状并且可以工作,不知道这是否是正确的做法。
    • 毗湿奴能给我你的邮箱吗?
    • @PedroMeira 因为这是公共网站,所以我无法分享我的个人 ID。您可以在此 FB acc facebook.com/ImadeInfotech 中留言您的邮件 ID
    【解决方案3】:

    UIScrollView 对 touchesEnded、touchesBegan、touchesMoved 等是免疫的。也就是说,它可以防止这些方法在 ViewControler 中被调用。

    可能性一:

    在ScrollView中使用UIGestureRecognizerDelegates实现触摸

    可能性2:

    创建 UIScrollView 类的子类并覆盖 touchesBegan: 和其他触摸方法

    希望对你有帮助!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-02
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多