【问题标题】:Create a UIImage with UIGestureRecognizer at runtime在运行时使用 UIGestureRecognizer 创建 UIImage
【发布时间】:2010-10-12 11:31:06
【问题描述】:

我希望能够添加一个特定大小的新 UIImageView,它应该有一些 UIGestureRecognizers 检测 UIImageView 上的触摸。

如何子类化 UIImageView 或如何最好地实现?

我希望用户能够在运行时根据需要添加 UIImageView,然后手势识别器将允许他们操作视图。

谢谢

【问题讨论】:

    标签: iphone uiimageview uigesturerecognizer


    【解决方案1】:

    我认为您只是忘记启用 userInteractions。

    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];
    

    【讨论】:

    • 我可以得到 UIImage 上的实际点击像素位置吗?
    猜你喜欢
    • 1970-01-01
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多