代码之家  ›  专栏  ›  技术社区  ›  some_id

在运行时使用uigesturerecognizer创建uiimage

  •  1
  • some_id  · 技术社区  · 15 年前

    我想能够添加一个新的uiImageView的一定大小,应该有几个uiGestureRecognizer检测触摸的uiImageView。

    一个子类uiImageView是如何实现的,还是如何实现的?

    我希望用户能够在运行时按需要添加uiImageView,然后GestureRecognizer将允许他们操纵视图。

    谢谢

    1 回复  |  直到 15 年前
        1
  •  8
  •   Matthias Bauch    15 年前

    我想你只是忘记了启用用户交互。

    UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"foo.png"]] autorelease];
    imageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)] autorelease];
    [imageView addGestureRecognizer:tapGesture];
    [self.view addSubview:imageView];