【问题标题】:I can not touch the image when using UIScrollView使用 UIScrollView 时我无法触摸图像
【发布时间】:2012-05-09 03:04:43
【问题描述】:

我使用 UIScrollView 显示UIImageView 的序列(UIImageView 被添加为scrollview 的子视图),问题是我重写了UIImageView 中的方法:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

但是当我点击图片时,没有调用该方法,好像图片没有收到点击事件。确切的原因是什么?我怎样才能解决这个问题? (我已经启用了 UIImageView 的 ExclusiveTouch 和所有视图的 User Interavtion)

【问题讨论】:

    标签: iphone objective-c uiscrollview


    【解决方案1】:

    将 UIImageView 的 exclusiveTouchuserInteractionEnabled 属性设置为 YES 并重试。我发现滚动视图的子视图只接收一些事件或不接收事件,并且设置 ExclusiveTouch 允许视图立即声明它们。

    【讨论】:

      【解决方案2】:

      设置

      imageView.userInteractionEnabled = YES;
      

      如果你只想要一个图像视图的点击事件

      只需使用 UITapGestureRecognizer

      UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
      [imageView addGestureRecognizer:tap];
      

      那么你必须实现方法

      - (void) tap:(UITapGestureRecognizer*)gesture
      {
          UIImageView *v = gesture.view;// that your ImageView tapped
      }
      

      【讨论】:

        【解决方案3】:

        imageView.userInteractionEnabled = NO;

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-02-10
          • 1970-01-01
          • 1970-01-01
          • 2016-04-24
          • 2023-03-06
          • 2016-07-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多