简体   繁体   中英

Incompatible pointer types sending 'UITapGestureRecognizer *' to parameter of type 'UIView * _Nonnull'

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

what's wrong with these code.
Xcode 7.0 gives this error :

Incompatible pointer types sending 'UITapGestureRecognizer *' to parameter of type 'UIView * _Nonnull'

You should use addGestureRecognizer for adding a gesture to a UI object

// [self.fullScreenImageView addSubview:tapGestureRecognizer];

[self.fullScreenImageView addGestureRecognizer: tapGestureRecognizer];
    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];

this is the solution. i found thanks @anhtu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM