(IOS)签名Demo
思路是将每一次按下屏幕的touch move时的点存到一个数组里,即一个数组相当于一个笔画;再将该代表笔画的数组保存到一个大数组中,每组每次touch的移动都历遍大数组和笔画数组,将点于点之间连接起来。
#import <UIKit/UIKit.h>
@interface BIDDrawView : UIView
{
NSMutableArray *allPoints;
} @end
#import "BIDDrawView.h" @implementation BIDDrawView - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
allPoints=[[NSMutableArray alloc] init]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame=CGRectMake(, , , );
[btn addTarget:self action:@selector(undo:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
}
return self;
} -(void)undo:(UIButton *)sender
{
if (allPoints.count>) { // 如果撤销有问题需要把该判断移除
[allPoints removeLastObject];
[self setNeedsDisplay];
}
} - (void)drawRect:(CGRect)rect
{
if (allPoints.count == ) {
return;
} CGContextRef ctx=UIGraphicsGetCurrentContext(); //获取画板,或者说获取画图上下文。
CGContextSetStrokeColorWithColor(ctx, [UIColor redColor].CGColor); //设置画笔颜色。
CGContextSetLineWidth(ctx, 1.5); //设置线条宽度。 for (NSMutableArray *points in allPoints) {
for (int i=;i<points.count-;i++) {
if (points.count==) {
break;
}
NSValue *sValue = [points objectAtIndex:i];
CGPoint sPoint=[sValue CGPointValue]; NSValue *eValue = [points objectAtIndex:i+];
CGPoint ePoint=[eValue CGPointValue]; CGContextMoveToPoint(ctx, sPoint.x, sPoint.y); //前往起点。
CGContextAddLineToPoint(ctx, ePoint.x, ePoint.y); //由起点加线到终点。 CGContextStrokePath(ctx);
}
}
} -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableArray *points = [NSMutableArray array];
[allPoints addObject:points];
} -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
NSValue *v = [NSValue valueWithCGPoint:p]; //CGPoint 转为 对象
NSMutableArray *points = [allPoints lastObject];
[points addObject:v];
//驱动画笔(drawRect方法)
[self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{}
@end
效果:
(IOS)签名Demo的更多相关文章
- 91平台iOS接入demo
源码:http://pan.baidu.com/s/1DuBl6 今天整理硬盘,找到了一个有趣的demo.一年前,91助手游戏联运呈爆棚趋势,但是许多使用FlashAir开发的优秀的游戏和应用都卡在了 ...
- iOS签名机制解析
最近遇到一个签名的问题,借机把iOS签名相关知识点研究了一下.现总结如下:(研究过程中参考了这位仁兄的博客.很全面,本文也有部分借鉴) 非对称加密 这个是签名机制的算法基础.所谓非对称加密的是相对于对 ...
- iOS开发系列-iOS签名机制
概述 想要了解iOS的签名机制需要有一定密码学有一定的了解.下面依次介绍的数据的加密解密.单向散列函数.数字签名.证书.iOS签名机制. 数据加密解密 在网络通信中想要防止数据被攻击者拦截,我们通常对 ...
- 光程科技IOS签名配置
光程科技IOS签名配置,APICloudAPP签名时config配置必须加上: <preference name="appCertificateVerify" value=& ...
- ios签名app稳定不掉签技术详细教程详解
iOS签名是专门针对ios的APP内测的数字签名,是苹果面向开发者提出的一箱机制. 因为现在苹果APP下载渠道只有App Store,还可以加上一个内测用的testflight,也就是说,除了这两个官 ...
- 03.WebView演练-iOS开发Demo(示例程序)源代码
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong //转载请注明出处--本文永久链接:h ...
- XMPP协议实现即时通讯底层书写 (二)-- IOS XMPPFramework Demo+分析
我希望,This is a new day! 在看代码之前,我认为你还是应该先整理一下心情,来听我说几句: 首先,我希望你是在早上边看这篇blog,然后一边開始动手操作,假设你仅仅是看blog而不去自 ...
- 适合新人学习的iOS官方Demo
UICatalog.包括了绝大部分经常使用的UI,入门必备良药. 9 分段选择器 10滑动条 Slider 11stack view 12 分步条 13 开关 14 textfield 15text ...
- vue项目中微信jssdk在ios签名失败
一.问题描述 1. vue项目中微信jssdk签名时,在安卓和ios是有差异的,签名时使用的url=window.location.href.split('#')[0],此时在安卓没问题,在ios会导 ...
随机推荐
- ZOJ 1698 (最大流入门)
Power NetworkTime Limit:5000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu SubmitStat ...
- python 类属性、对象属性
类的普通属性: dir(Myclass), 返回一个key列表: Myclass.__dir__,返回一个字典: 1.类的数据属性: 2.类的方法: 类的特殊属性: 1.Myclass.__name_ ...
- ASP.NET WebApi 简单记录
//获取当前提交过来的Request对象 var request = System.Web.HttpContext.Current.Request;
- 未能加载文件或程序集“**, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。试图加载格式不正确的程序。
未能加载文件或程序集“Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项.试图加载格式不正确的程序. 原来, ...
- XGPush集成(信鸽集成)demo
#import "AppDelegate.h" #import "XGPush.h" #import "XGSetting.h" #defi ...
- 网络编程——TCP连接
TCP在双方传输数据前,发送方先请求建立连接,接收方同意建立连接后才能传输数据.(打电话:先拨号,等对方同意接听后,才能交流)...高可靠性 UDP不需要建立连接(发短信).不可靠,可能出现数据丢失等 ...
- [置顶] 两主机搭建MySQL主从复制后,show slave status显示:Last_IO_Error: error connecting to master ……
两台主机A.B搭建mysql主从复制关系(A为master,B为slave)后,在slave上执行show slave status,结果中显示Last_IO_Error: error connect ...
- sourceTree安装与使用
1,下载并安装 sourceTree http://downloads.atlassian.com/software/sourcetree/windows/SourceTreeSetup_1.6.14 ...
- [LeetCode]题解(python):075-Sort Colors
题目来源: https://leetcode.com/problems/sort-colors/ 题意分析: 给定n个颜色,红色,白色和蓝色.分别用0,1,2代替,将这些颜色排序,0在1前,1在2前. ...
- Cyclomatic complexity
Cyclomatic Code Complexity was first introduced by Thomas McCabe in 1976. In 1976, Thomas McCabe pub ...