Removing image from UIImageView

前端 未结 5 931
清酒与你
清酒与你 2021-02-01 00:44

I load a UIImageView with an image depending on user interaction. When the parent view is initially displayed, no image has been selected and the imageview is blac

5条回答
  •  遥遥无期
    2021-02-01 01:04

    You can use a UITapGestureRecognizer to remove the image for a given number of clicks.

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onImageTapped:)];
    
    tapGesture.delegate = self;
    
    tapGesture.numberOfTapsRequired = 2; // no. of taps (clicks) on which you want to remove the image
    
    [myImageView addGestureRecognizer:tapGesture];
    

    and give the method's definition:

    - (void)onImageTapped:(UITapGestureRecognizer*)recognizer
    {
    
        UIImageView *imgView = (UIImageView*) recognizer.view;
        [imgView removeFromSuperview];
    }
    

提交回复
热议问题