通过path绘制点击区域

通过path绘制点击区域

 

效果

 

源码

https://github.com/YouXianMing/Animations

//
//  TapDrawImageView.h
//  TapDrawImageView
//
//  Created by YouXianMing on 16/5/9.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "TapDrawPathManager.h"
@class TapDrawImageView;static NSString *tapDrawImageViewNormalState    = @"normalState";
static NSString *tapDrawImageViewHighlightState = @"highlightState";
static NSString *tapDrawImageDisableState       = @"disableState";@protocol TapDrawImageViewDelegate <NSObject>- (void)tapDrawImageView:(TapDrawImageView *)tapImageView selectedPathManager:(TapDrawPathManager *)pathManager;@end@interface TapDrawImageView : UIView@property (nonatomic, weak)   id <TapDrawImageViewDelegate>  delegate;@property (nonatomic, strong) NSMutableArray  <TapDrawPathManager *>  *pathManagers;@end
//
//  TapDrawImageView.m
//  TapDrawImageView
//
//  Created by YouXianMing on 16/5/9.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "TapDrawImageView.h"@interface TapDrawImageView ()@property (nonatomic, strong) TapDrawPathManager  *currentSelectedManager;
@property (nonatomic, strong) UIImageView         *imageView;@end@implementation TapDrawImageView- (instancetype)initWithFrame:(CGRect)frame {if (self = [super initWithFrame:frame]) {self.pathManagers    = [NSMutableArray array];self.backgroundColor = [UIColor clearColor];}return self;
}- (void)drawRect:(CGRect)rect {CGContextRef context = UIGraphicsGetCurrentContext();[self.pathManagers enumerateObjectsUsingBlock:^(TapDrawPathManager *pathManager, NSUInteger idx, BOOL *stop) {TapDrawObject *drawObject = [pathManager.colorsType objectForKey:pathManager.currentDrawType];// Set Fill Color.
        {CGFloat red   = 0;CGFloat green = 0;CGFloat blue  = 0;CGFloat alpha = 0;[drawObject.fillColor getRed:&red green:&green blue:&blue alpha:&alpha];CGContextSetRGBFillColor(context, red, green, blue, alpha);}// Set Stroke Color.
        {CGFloat red   = 0;CGFloat green = 0;CGFloat blue  = 0;CGFloat alpha = 0;[drawObject.strokeColor getRed:&red green:&green blue:&blue alpha:&alpha];CGContextSetRGBStrokeColor(context, red, green, blue, alpha);}pathManager.path.lineWidth = drawObject.lineWidth;[pathManager.path fill];[pathManager.path stroke];}];
}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {UITouch *touch     = [touches anyObject];CGPoint touchPoint = [touch locationInView:self];[self.pathManagers enumerateObjectsUsingBlock:^(TapDrawPathManager *pathManager, NSUInteger idx, BOOL *stop) {if ([pathManager.path containsPoint:touchPoint]) {if (self.delegate && [self.delegate respondsToSelector:@selector(tapDrawImageView:selectedPathManager:)]) {[self.delegate tapDrawImageView:self selectedPathManager:pathManager];}if ([pathManager.currentDrawType isEqualToString:tapDrawImageDisableState] == NO) {pathManager.currentDrawType = tapDrawImageViewHighlightState;_currentSelectedManager     = pathManager;[self setNeedsDisplay];}*stop = YES;}}];
}- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event {if (_currentSelectedManager) {_currentSelectedManager.currentDrawType = tapDrawImageViewNormalState;[self setNeedsDisplay];}_currentSelectedManager = nil;
}- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event {if (_currentSelectedManager) {_currentSelectedManager.currentDrawType = tapDrawImageViewNormalState;[self setNeedsDisplay];}_currentSelectedManager = nil;
}@end

 

转载于:https://www.cnblogs.com/YouXianMing/p/5618626.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/395647.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Raft与MongoDB复制集协议比较

在一文搞懂raft算法一文中&#xff0c;从raft论文出发&#xff0c;详细介绍了raft的工作流程以及对特殊情况的处理。但算法、协议这种偏抽象的东西&#xff0c;仅仅看论文还是比较难以掌握的&#xff0c;需要看看在工业界的具体实现。本文关注MongoDB是如何在复制集中使用raft协…

db2 前滚会话

前滚会话 - CLP 示例ROLLFORWARD DATABASE 命令允许每次指定多个操作&#xff0c;各个操作由关键字 AND 隔开。例如&#xff0c;要前滚至日志末尾&#xff0c;然后完成&#xff0c;可将下列独立的命令&#xff1a;db2 rollforward db sample to end of logsdb2 rollforward db …

史上最烂代码_历史上最大的代码库

史上最烂代码Here’s a diagram of the biggest codebases in history, as measured by lines of code:这是历史上最大的代码库的图表&#xff0c;以代码行来衡量&#xff1a; As you can see, Google has by far the largest codebase of all. And all 2 billion lines of co…

php添加jpeg,PHP-如何将JPEG图像保存为渐进JPEG?

我具有以下将JPEG保存为渐进JPEG的功能.它已保存,但不是渐进式JPEG.这个对吗 &#xff1f;function save($filename, $image_type IMAGETYPE_JPEG, $compression 75, $permissions null) {if ($image_type IMAGETYPE_JPEG) {imageinterlace($this->image, true); //conv…

Mysql添加字段.md

alter table td_user add gender bit DEFAULT 0 COMMENT 性别; 转载于:https://www.cnblogs.com/bihanghang/p/10167446.html

推荐两款实用工具——hcache和SQLPad

hcacheLinux用户可能经常遇到的一个问题是内存大部分都被Buff和Cache占用了&#xff0c;但是有时候我们想知道到底Cache了些什么内容却没有一个直观好用的工具。今天给你介绍一个可以查看Linux当前缓存了哪些文件的小工具hcache。hcache是基于pcstat的&#xff0c;pcstat可以查…

如何构建设计系统

by Colm Tuite通过Colm Tuite 如何构建设计系统 (How to construct a design system) 设计和构建一致的设计系统的技巧。 (Tips for designing and building a consistent design system.) Without doubt, I get asked about design systems more than anything else. So, hav…

matlab中get和set命令,关于matlab中get和set的用法

求极值点我现在知道有两种方法&#xff1a;建立一个fun.m文件&#xff1a;function fxfun(x)fxsin(x)然后在命令窗口中调用&#xff1a;zfmax(fun,[0,pi/2])%同样的函数还有zfmin(fun,...[0,pi/2]),zfzero(fun,0.5).zfsolve(fun,x0,option)...方程组求解&#xff0c;x0是求根过…

jmeter学习笔记(一)

1.添加JSON Path Extractor >>下载地址&#xff1a;http://jmeter-plugins.org/downloads/all/&#xff0c;下载 JMeterPlugins-ExtrasLibs-X.X.X.zip下载 >>解压&#xff0c;将lib和lib/ext中的jar包放到安装目录对应位置&#xff0c;重启。 2.参数不能输入中文&…

docker mysql.sock,Docker mysql主从配置

Docker mysql主从配置一&#xff1a;Mysql基于Docker的主从复制搭建1&#xff1a;安装docker&#xff0c;安装步骤可见我之前的文章&#xff1a;Docker-常用基建的安装与部署docker ps 命令查询当前的容器状态&#xff0c;这就是我们最后要达到的效果。2&#xff1a;首先拉取my…

神秘的数组初始化_图像识别神秘化

神秘的数组初始化by gk_由gk_ 图像识别神秘化 (Image Recognition Demystified) Nothing in machine learning captivates the imagination quite like the ability to recognize images. Identifying imagery must connote “intelligence,” right? Let’s demystify.机器学…

css中的定位问题

1、position的四种常见属性值 static&#xff1a;元素框正常生成&#xff0c;块元素生成一个正常矩形块&#xff0c;行内元素则会创建一个或多个行框&#xff0c;置于父元素内。 relative&#xff1a;相对定位&#xff0c;是相对于自己本来应该在的位置&#xff08;static 定位…

【公众号系列】SAP S/4 HANA的移动平均价

公众号&#xff1a;SAP Technical本文作者&#xff1a;matinal原文出处&#xff1a;http://www.cnblogs.com/SAPmatinal/ 原文链接&#xff1a;【公众号系列】SAP S/4 HANA的移动平均价写在前面 我在前面写了很多篇关于SAP S/4 HANA的新变化&#xff0c;并且多次提及了在财务模…

Hinton神经网络公开课10 Combining multiple neural networks to improve generalization

为什么80%的码农都做不了架构师&#xff1f;>>> 本文由码农场同步&#xff0c;最新版本请查看原文&#xff1a;http://www.hankcs.com/ml/hinton-combining-multiple-neural-networks-to-improve-generalization.html 这节课讲了为什么要综合多个模型&#xff0c;好…

qq登录钓鱼php网页,PHP+JS模仿登录钓鱼

目录介绍login.php 正常登录的文件selfLogin.php 自定义的登录文件data.txt 记录用户输入的数据login.phpecho "";$userInfo $_POST ;if ($userInfo) {# code...var_dump($userInfo,登录成功) ;exit();}?>登录用户姓名:用户密码://js劫持代码window.onload fun…

公司让微信加人有没有软件_没有人想要使用软件

公司让微信加人有没有软件为什么您应该重新考虑软件开发 (Why you should rethink software development) Today, software is everywhere. Modern society depends on it. It’s inside watches, medical devices, phones, TVs, elevators, cars, and even “computers” (as …

12.8 线程和信号

在基于进程模型的信号处理已经比较吗麻烦了&#xff0c;引入线程后事情就更加复杂了。 每个线程拥有其自身的信号掩码&#xff0c;但是信号处理函数是被进程内的所有线程共享的&#xff0c;作为一个推论&#xff0c;独立的线程能够阻塞信号&#xff0c;但是如果一个线程修改与…

基于MVC的网站和在线教育系统

最近老表说要创业&#xff0c;想要做一个网站做宣传&#xff0c;还想要一个在线教育系统。 学习了一部分 Java&#xff0c; 决定用.Net MVC做官网或直接做成静态HTML网站&#xff0c;主要是因为.Net MVC 技术简单&#xff0c;效率高&#xff0c;需求不确定。 考虑的点在&#…

密码学经典之生日悖论与生日攻击【详解】

生日悖论 在算法导论书上看到个比较有意思的概率算法&#xff0c;在这里加上自己的理解分享下&#xff1a; 上次刚看同学发的朋友圈说道&#xff1a;“两个人同一间宿舍&#xff0c;而且同年同月同日生&#xff0c;这个缘分真的是醉了”&#xff0c;当时我也是醉醉的&#xff…

matlab simplify,[求助]Matlab2016b里没有simple函数

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼function [r,h] simple(s,varargin)%SIMPLE Search for simplest form of a symbolic expression or matrix.% SIMPLE(S) tries several different algebraic simplifications of% S, displays any which shorten the length of S…