UIImageView
s have userInteractionEnabled
set to NO
by default. You have to set imageView.userInteractionEnabled = YES;
.
UILongPressGestureRecognizer in subview didnot work [duplicate]
-
03-07-2022 - |
Question
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect imageRect = (CGRect){105, 180, 110, 110};
UIImage *image = [UIImage imageNamed: @"sasuke.png"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageRect];
[imageView setImage: image];
UILongPressGestureRecognizer *longGnizer=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longGo:)];
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:longGnizer];
[self.view addSubview:imageView];
}
- (void)longGo:(UILongPressGestureRecognizer *)aGer{
if(aGer.state==UIGestureRecognizerStateBegan) {
NSLog(@"%s",__func__);
}
}
here's the code ,but the func longGo were never work,why?when I use[self.view addGestureRecognizer:longGnizer],it did works.
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow