objective-c - 如何关闭全屏 UIImageView?
问题描述
在我的应用程序中单击按钮时,我正在创建这样的 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];
但是,当它被点击时,我如何消除相同的视图?
解决方案
您可以添加UITapGestureRecognizer
您的UIImageView
并在其操作中删除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
.UITapGestureRecognizer
- (void)dismissTapGesture:(UITapGestureRecognizer*)gesture {
[gesture.view removeFromSuperview];
}
推荐阅读
- python - 同时运行的多个 Python 实例限制为 35 个
- c++ - 如何在 C++ (sfml) 中获取图像中像素的颜色
- ios - 点击 addsubview 事件按钮
- coinbase-api - Coinbase Pro API 删除所有订单
- c# - How can I release ListView's source memory?
- javascript - 检查一个javascript数组是否包含另一个数组的所有值
- python - 如何在python随机森林模型中删除可预测值(y)
- javascript - 拼接后更新 JSON 文件
- jquery - 如何删除在 js.cookie.min.js jQuery 中存储为数组的 cookie 值?
- windows - windows编程中“进程名”的定义是什么?