IOS 多个ImageView图片层叠透明区域点击事件穿透
经常用到多个透明图片层叠,但又需要获取不同图片的点击事件,本文实现图片透明区域穿透点击事件
实现人体各个部位点击
- - (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event
- {
- CGPoint shoulderPoint = [self getNewPoint:point SetImage:shouldImage];
- if(CGRectContainsPoint(shouldImage.bounds,shoulderPoint)) {
- if ([self isAplphaSetPoint:shoulderPoint andSetImage:shouldImage]) {
- shouldImage.image = [UIImage imageNamed:@"man_shoulder_pressed"];
- return YES;
- }
- }
- return YES;
- }
- #param point点转换
- -(CGPoint) getNewPoint:(CGPoint) point SetImage:(UIImageView *) iv {
- return CGPointMake(point.x - iv.frame.origin.x,
- point.y - iv.frame.origin.y);
- }
- -(BOOL) isAplphaSetPoint:(CGPoint) point andSetImage:(UIImageView *) iv {
- NSLog(@"point: %f", point.y);
- UIColor *uColor = [self colorAtPixel: point setImage: iv];
- const CGFloat *components = CGColorGetComponents(uColor.CGColor);
- if (NULL != components) {
- NSLog(@"Red: %f Green: %f Blue: %f alpha: %f", components[0], components[1], components[2], components[3]);
- float aplphaF = components[3];
- if ((aplphaF >= 0.5)) {
- return YES;
- }
- }
- return NO;
- }
- #param 点击时间结束 逻辑处理
- -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- }
- - (UIColor *)colorAtPixel:(CGPoint)point setImage: (UIImageView *) iv {
- if (!CGRectContainsPoint(CGRectMake(0.0f, 0.0f, iv.frame.size.width, iv.frame.size.height), point)) {
- return nil;
- }
- NSInteger pointX = trunc(point.x);
- NSInteger pointY = trunc(point.y);
- CGImageRef cgImage = iv.image.CGImage;
- NSUInteger width = iv.frame.size.width;
- NSUInteger height = iv.frame.size.height;
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- int bytesPerPixel = 4;
- int bytesPerRow = bytesPerPixel * 1;
- NSUInteger bitsPerComponent = 8;
- unsigned char pixelData[4] = { 0, 0, 0, 0 };
- CGContextRef context = CGBitmapContextCreate(pixelData,
- 1,
- 1,
- bitsPerComponent,
- bytesPerRow,
- colorSpace,
- kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
- CGColorSpaceRelease(colorSpace);
- CGContextSetBlendMode(context, kCGBlendModeCopy);
- // Draw the pixel we are interested in onto the bitmap context
- CGContextTranslateCTM(context, -pointX, pointY-(CGFloat)height);
- CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, (CGFloat)width, (CGFloat)height), cgImage);
- CGContextRelease(context);
- // Convert color values [0..255] to floats [0.0..1.0]
- CGFloat red = (CGFloat)pixelData[0] / 255.0f;
- CGFloat green = (CGFloat)pixelData[1] / 255.0f;
- CGFloat blue = (CGFloat)pixelData[2] / 255.0f;
- CGFloat alpha = (CGFloat)pixelData[3] / 255.0f;
- return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
- }
IOS 多个ImageView图片层叠透明区域点击事件穿透的更多相关文章
- iOS 使点击事件穿透透明的UIView
如图: 悬浮的三个按钮下方有一个可以点击的灰色区域,但是点击按钮之间的透明区域, 这三个按钮的contentView会响应这个点击事件,这时候需要让这个contentView不响应这个点击事件. 解决 ...
- Android EditText中插入图片并响应点击事件
EditText中插入图片基本就是两种方法: ,通过Html.fromHtml(..)来实现 [mw_shl_code=java,true]eText.append(Html.fromHtml(&qu ...
- IOS开发中如何给UIImageView添加点击事件
1.先创建一个UIImageView控件: photeImageView = [[UIImageView alloc]init]; photeImageView.frame = CGRectMake( ...
- iOS全埋点解决方案-控件点击事件
前言 我们主要介绍如何实现控件点击事件($AppClick)的全埋点.在介绍如何实现之前,我们需要先了解一下,在 UIKit 框架下,处理点击或拖动事件的 Target-Action 设计模式. ...
- iOS UITapGestureRecognizer手势和UIButton 以及UITabelView点击事件冲突
一:在同一个view上加载,UITapGestureRecognizer手势,UIButton 行为,UITabelView点击事件冲突: 二:解决方式: 在UITapGesttureRecogniz ...
- ios 给移动的控件添加点击事件
前言: 给一个UIView做移动动画,虽然看起来frame在持续改变,但是它的frame已经是最终值了. 也就是说表面看到的动画都是假象,它的真实位置已经是固定的了.所以只有点击在他的真实frame范 ...
- ios执行失去焦点,不执行点击事件
原因:由于JavaScript为单线程,同一时间只能执行处理一个事件.“blur优先于click执行”.而在本示例中,由于blur处理程序,会将对下拉框展示区隐藏,所以导致其后续click事件并不会执 ...
- Android ImageView图片透明区域不响应点击事件,不规则图片透明区域响应点击事件
转载:http://blog.csdn.net/aminfo/article/details/7872681 经常会在项目中用到透明图片,不规则图片,特别是做游戏的时候,需要对图片的透明区域的点击事件 ...
- iOS开发之ImageView复用实现图片无限轮播
在上篇博客中iOS开发之多图片无缝滚动组件封装与使用给出了图片无限轮播的实现方案之一,下面在给出另一种解决方案.今天博客中要说的就是在ScrollView上贴两个ImageView, 把ImageVi ...
随机推荐
- PHP中的设计模式:单例模式(译)
原文链接:http://coderoncode.com/2014/01/27/design-patterns-php-singletons.html 单例模式用于限制类实例化到单个对象,当整个系统只需 ...
- iOS: XCode6 beta 6 错误
在使用XCode6 Beta6时, 遇到"__TFSs15_arrayForceCastU___FGSaQ__GSaQ0__"错误: 在http://stackoverflow.c ...
- WebApi(四)-Post接口请求失败或接受不到参数(解决方法)
post方式只能接受一个参数而且必须用FromBody特性标识,所以当没有使用FromBody特性标识的时候就会请求失败,如有添加添加了那访问接口时候参数应传对象不能是key:val的格式否则会接收到 ...
- BASLER 镜头选型白皮书
本文翻译自Basler镜头选型白皮书 有许多方法来进行镜头选型.本文将会讨论其中的指导原则,以帮助你在项目中选择合适的镜头.我们将讨论许多镜头的基本概念,比如镜头接口.图像大小.放大率.焦距.F数和光 ...
- 什么是image crop?
一直对image crop很困惑,总算是看到了一篇描述较为简洁的说明:图像crop就是指从图像中移除不需要的信息,只保留需要的部分
- 利用R进行多元线性回归分析
对于一个因变量y,n个自变量x1,...,xn,要如何判断y与这n个自变量之间是否存在线性关系呢? 肯定是要利用他们的数据集,假设数据集中有m个样本,那么,每个样本都分别对应着一个因变量和一个n维的自 ...
- 应用Java(环境变量)
工作中,不一定非要设置Java环境变量 因为,IDE自身环境的设置,代替了系统环境变量 环境变量 系统的环境变量,相当于软件工作的环境.工作中,经常需要设置以下变量: Path ClassPath 自 ...
- 关于@synchronized(self)的用法
@synchronized 的作用是创建一个互斥锁,保证此时没有其它线程对self对象进行修改.这个是objective-c的一个锁定令牌,防止self对象在同一时间内被其它线程访问,起到线程的保护作 ...
- Python安装及开发环境配置
Python的语法简洁,功能强大,有大量的第三方开发包(模块).同时Python不像java一样对内存要求非常高,适合做一些经常性的任务方面的编程.根据codeeval网站数据统计显示,连续三年,Py ...
- ArtisticStyle----很好用的C/C++样式格式化工具
下载地址:http://srgb.googlecode.com/files/AStyle_2.02_windows.7z 把astyle.exe 复制到 C:\WINDOWS 目录里,省的指定路径VC ...