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 ...
随机推荐
- LICAppInfo
[Common] Enabled=true All=true [AppList] #AppName #Enabled #Validit ...
- 基于Lua的清除类游戏算法
最近在开发游戏,用Lua语言.习惯了其它的语言,然后对Lua的一些语法很不习惯. 比如table的元素个数的取值,比switch语句等等. 不过没有办法,还是要运用Lua来写游戏的.看来学C++还真的 ...
- 【转】改善C#程序的建议2:C#中dynamic的正确用法 空间
dynamic是FrameWork4.0的新特性.dynamic的出现让C#具有了弱语言类型的特性.编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性.比如,即使你 ...
- PHP之路——Redis安装
windows: redis下载链接:https://github.com/ServiceStack/redis-windows 然后编辑redis.windows.conf文件,我看网上有的教程说编 ...
- register 不允许 block 模式,而默认的是
Exception in thread "main" java.nio.channels.IllegalBlockingModeException at java.nio.chan ...
- NEURAL NETWORKS, PART 3: THE NETWORK
NEURAL NETWORKS, PART 3: THE NETWORK We have learned about individual neurons in the previous sectio ...
- h.264并行解码算法2D-Wave实现(基于多核非共享内存系统)
在<Scalable Parallel Programming Applied to H.264/AVC Decoding>书中,作者基于双芯片18核的Cell BE系统实现了2D-Wav ...
- 解除網頁無法選取文字、鎖右鍵限制:Enable Copy(Chrome 擴充套件)
有些网页因会因为某些因素而禁止浏览者直接复制网页上的内容,虽然我们了解站方的意思,不过有些时候会造成一些不必要的困扰. Enable Copy 这款Chrome 扩充套件可以帮你一键解除封锁右键和选取 ...
- 去大公司还是去小公司工作——要进大公司的核心部门(提升视野,锻炼技能),远离没真本事的小公司,要自我驱动 good
去大公司还是小公司工作?这个问题问大多数 IT 人都会选择前者.如果换一个问法,去大公司还是去初创公司(Startup)工作?或许有极小一部分人能改变一下决定 对于 IT 人来说,选择到大公司工作的理 ...
- .rdp 文件参数详解
Overview of .rdp file settings Setting Type Default value Description and possible values Settable f ...