【发布时间】:2010-10-12 11:31:06
【问题描述】:
我希望能够添加一个特定大小的新 UIImageView,它应该有一些 UIGestureRecognizers 检测 UIImageView 上的触摸。
如何子类化 UIImageView 或如何最好地实现?
我希望用户能够在运行时根据需要添加 UIImageView,然后手势识别器将允许他们操作视图。
谢谢
【问题讨论】:
标签: iphone uiimageview uigesturerecognizer
我希望能够添加一个特定大小的新 UIImageView,它应该有一些 UIGestureRecognizers 检测 UIImageView 上的触摸。
如何子类化 UIImageView 或如何最好地实现?
我希望用户能够在运行时根据需要添加 UIImageView,然后手势识别器将允许他们操作视图。
谢谢
【问题讨论】:
标签: iphone uiimageview uigesturerecognizer
我认为您只是忘记启用 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];
【讨论】: