Objective c 如何取消全屏UIImageView?

Objective c 如何取消全屏UIImageView?,objective-c,uiimageview,Objective C,Uiimageview,当在我的应用程序中单击一个按钮时,我正在创建这样的UIImageView CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screenRect.size.height; NSData *imageData = [NSData dataWithContentsOfURL:[NSURL

当在我的应用程序中单击一个按钮时,我正在创建这样的UIImageView

CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;

    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:selectedVariantDetail[@"fcVariantImageUrl"]]];

    UIImageView *dot =[[UIImageView alloc] initWithFrame:CGRectMake(0,0,screenWidth,screenHeight)];
    dot.image=[UIImage imageWithData:imageData];
    dot.tag = 2;
    [self.view addSubview:dot];

但是,当点击同一视图时,如何关闭它?

您可以在
UIImageView
中添加
UIAppgestureRecognitizer
,并在其操作中删除
UIImageView

//Add tap Gesture
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissTapGesture:)];
[dot addGestureRecognizer:tapGesture];
//Set userInteractionEnabled property of imageView to true because by defaults its false
dot.userInteractionEnabled = YES;
现在只需删除
UIImageView
UIApgestureRecognitizer
中的操作方法

- (void)dismissTapGesture:(UITapGestureRecognizer*)gesture {
    [gesture.view removeFromSuperview];
}