开发者

Create a UIImage with UIGestureRecognizer at runtime

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜