UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction)];
tapGestureRecognizer.numberOfTapsRequired = 1;
self.fullScreenImageView = [[UIImageView alloc]initWithFrame:self.frame];
self.fullScreenImageView.image = [UIImage imageNamed:@"family"];
self.fullScreenImageView.userInteractionEnabled = YES;
[self addSubview:self.fullScreenImageView];
[self.fullScreenImageView addSubview:tapGestureRecognizer];
这些代码有什么问题。
Xcode 7.0给出了这个错误:
不兼容的指针类型发送' UITapGestureRecognizer *'至 类型参数' UIView * _Nonnull'
答案 0 :(得分:0)
您应该使用addGestureRecognizer
向UI对象添加手势
// [self.fullScreenImageView addSubview:tapGestureRecognizer];
[self.fullScreenImageView addGestureRecognizer: tapGestureRecognizer];
答案 1 :(得分:0)
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[self addGestureRecognizer:tapGestureRecognizer];
self.fullScreenImageView = [[UIImageView alloc]initWithFrame:self.frame];
self.fullScreenImageView.image = [UIImage imageNamed:@"family"];
self.fullScreenImageView.userInteractionEnabled = YES;
[self addSubview:self.fullScreenImageView];
这是解决方案。我发现了感谢@anhtu