在运行时使用 UIGestureRecognizer 创建 UIImage

发布于 2024-09-27 02:15:35 字数 204 浏览 2 评论 0原文

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

如何子类化 UIImageView 或者如何最好地实现这一点?

我希望用户能够在运行时添加他们想要的 UIImageViews,然后gestureRecognizer将允许他们操作视图。

谢谢

I would like to be able to add a new UIImageView of a certain size which should have a few UIGestureRecognizers detecting touch on the UIImageView.

How does one subclass UIImageView or how would this be best achieved?

I want the user to be able to add UIImageViews as they want at runtime and then the gestureRecognizer will allow them to manipulate the views.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月棠 2024-10-04 02:15:35

我认为您只是忘记启用 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];

I think you just forgot to enable 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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文