我在屏幕上有一张照片,当我拿着它时,我想以全尺寸显示。这是手势识别器:
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 正确触发。