通過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.pswp.cn/news/395647.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395647.shtml
英文地址,請注明出處:http://en.pswp.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…