屏幕上有一张图片需要在停留的时候全屏。
UILongPressGestureRecognizer *hold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hold:)];
hold.minimumPressDuration = 0;
[self.photoImageView addGestureRecognizer:hold];
监听器:
-(void)hold:(UILongPressGestureRecognizer *)sender{
UIImageView *img = [[UIImageView alloc] initWithImage:self.photo];
img.userInteractionEnabled = NO;
if(sender.state == UIGestureRecognizerStateBegan){
NSLog(@"state began");
[self.view addSubview:img];
} else if (sender.state == UIGestureRecognizerStateEnded){
NSLog(@"state ended");
[img removeFromSuperview];
}
}
图片成功添加到屏幕中,只有 [img removeFromSuperview]好像没有响应。
结束状态的NSlog也正常。