不兼容的指针类型发送' UITapGestureRecognizer *'参数类型' UIView * _Nonnull'

时间:2015-10-23 08:27:45

标签: ios objective-c iphone xcode7

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'

2 个答案:

答案 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