(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会导 ...
随机推荐
- mongodb初体验
最近关注大数据,自然会关注到nosql数据库,其中当然是mongodb. nosql数据库大多是k,v数据库,这也不是新鲜的名词了,berkerly DB已经存在很多年了,现在属于oracle. 具体 ...
- linux下安装python3.3.4
下载安装包 # wget http://www.python.org/ftp/python/3.3.4/Python-3.3.4.tgz 解压 # tar -xzvf Python-3.3.4.tgz ...
- android媒体--图库与API层MediaPlayer的交互
众所周知一个媒体播放器新建的几个步骤: Mediaplayer mp = new MediaPlayer(0 mp.setDatasource(xxx); mp.setDispalyer(xxx); ...
- 倒计时IE6+
很简单的 下面是我为了做多个倒计时更改之后的 dome 下载链接 兼容 IE7以上 IE6没测试应该没问题 http://yunpan.cn/cf29rxmGKuMyJ 提取码 ca61
- Img垂直居中
IMG垂直居中问题 2011-02-22 10:51:00| 分类: CSS | 标签:垂直居中 div align img vertical |举报|字号 订阅 转载来自:htt ...
- Java中布尔类型操作符&=,|=与^=的使用
今天在对同事的代码进行code review的时候,见到一个比较好玩的写法.“flag &= false:”,乍一看,还感觉他写错了,但是程序可以正常运行,赶紧去百度,看一下这个写法到底是怎么 ...
- ajax验证码检测
1.验证码文件 <%@ page language="java" pageEncoding="UTF-8"%> <%@ page conten ...
- [Swust OJ 838]--最优价值(0-1背包+数学)
题目链接:http://acm.swust.edu.cn/problem/838/ Time limit(ms): 1000 Memory limit(kb): 10000 Description 我 ...
- POJ 2689 Prime Distance(素数筛选)
题目链接:http://poj.org/problem?id=2689 题意:给出一个区间[L, R],找出区间内相连的,距离最近和距离最远的两个素数对.其中(1<=L<R<=2,1 ...
- C# DES加解密
加密 public static string Encrypt(string sourceString, string key, string iv) { try { byte[] btKey = E ...