ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:18.10KB ,
资源ID:6906817      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6906817.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(ios绘图.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

ios绘图.docx

1、ios绘图/ ViewController.m/ 01-带有边框的图片裁剪/ Created by Gavin on 15/9/14./ Copyright (c) 2015年 Gavin. All rights reserved./#import ViewController.h#import UIImage+image.hinterface ViewController ()property (weak, nonatomic) IBOutlet UIImageView *imageV;endimplementation ViewController- (void)viewDidLoad s

2、uper viewDidLoad; /1.加载 UIImage *image = UIImage imageNamed:阿狸头像; /2.边框宽度 CGFloat borderW = 10; /3.开启图片上下文. CGSize size = CGSizeMake(image.size.width + 2 * borderW, image.size.height + 2 * borderW); UIGraphicsBeginImageContextWithOptions(size, NO, 0); /4.先描述一个大圆,设为填充 UIBezierPath *path = UIBezierPat

3、h bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height); UIColor redColor set; path fill; /5.再添加一个小圆,把小圆设裁剪区域 path = UIBezierPath bezierPathWithOvalInRect:CGRectMake(borderW, borderW, image.size.width, image.size.height); path addClip; /6.把图片给绘制上下文. image drawInRect:CGRectMake(borderW,

4、borderW, image.size.width, image.size.height); /7.生成一张新的图片 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); /8.关闭上下文. UIGraphicsEndImageContext(); / 抽取出来的功能 self.imageV.image = UIImage imageWithBorderWidth:10 borderColor:UIColor greenColor image:UIImage imageNamed:阿狸头像;- (UIImage *)i

5、mageWithBorderWidth:(CGFloat)borderW borderColor:(UIColor *)color image:(UIImage *)image /3.开启图片上下文. CGSize size = CGSizeMake(image.size.width + 2 * borderW, image.size.height + 2 * borderW); UIGraphicsBeginImageContextWithOptions(size, NO, 0); /4.先描述一个大圆,设为填充 UIBezierPath *path = UIBezierPath bezie

6、rPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height); /设置边框的颜色 color set; path fill; /5.再添加一个小圆,把小圆设裁剪区域 path = UIBezierPath bezierPathWithOvalInRect:CGRectMake(borderW, borderW, image.size.width, image.size.height); path addClip; /6.把图片给绘制上下文. image drawInRect:CGRectMake(borderW, borderW,

7、image.size.width, image.size.height); /7.生成一张新的图片 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); /8.关闭上下文. UIGraphicsEndImageContext(); return newImage; - (void)didReceiveMemoryWarning super didReceiveMemoryWarning; / Dispose of any resources that can be recreated.end/ UIImage+imag

8、e.m/ 01-带有边框的图片裁剪/ Created by Gavin on 15/9/14./ Copyright (c) 2015年 Gavin. All rights reserved./#import UIImage+image.himplementation UIImage (image)+ (UIImage *)imageWithBorderWidth:(CGFloat)borderW borderColor:(UIColor *)color image:(UIImage *)image /3.开启图片上下文. CGSize size = CGSizeMake(image.size

9、.width + 2 * borderW, image.size.height + 2 * borderW); UIGraphicsBeginImageContextWithOptions(size, NO, 0); /4.先描述一个大圆,设为填充 UIBezierPath *path = UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height); /设置边框的颜色 color set; path fill; /5.再添加一个小圆,把小圆设裁剪区域 path = UIBezierPath be

10、zierPathWithOvalInRect:CGRectMake(borderW, borderW, image.size.width, image.size.height); path addClip; /6.把图片给绘制上下文. image drawInRect:CGRectMake(borderW, borderW, image.size.width, image.size.height); /7.生成一张新的图片 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); /8.关闭上下文. UIGraphicsE

11、ndImageContext(); return newImage; end/ ViewController.m/ 02-截屏/ Created by Gavin on 15/9/14./ Copyright (c) 2015年 Gavin. All rights reserved./#import ViewController.hinterface ViewController ()endimplementation ViewController- (void)viewDidLoad super viewDidLoad; / Do any additional setup after loa

12、ding the view, typically from a nib.-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event /1.开启图片上下文. UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0); /获取当前的上下文. CGContextRef ctx = UIGraphicsGetCurrentContext(); /UIView之所能够显示,是因为它内部有一个层,layer.层是通过渲染的方法,给绘制上下文. self.vie

13、w.layer renderInContext:ctx; /生成一张图片. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); /如何把图片转换成二进流. NSData *data = UIImagePNGRepresentation(newImage); data writeToFile:/Users/gaoxinqiang/Desktop/newImage.png atomically:YES; /关闭上下文. UIGraphicsEndImageContext(); - (void)didReceiveMemo

14、ryWarning super didReceiveMemoryWarning; / Dispose of any resources that can be recreated.end/ ViewController.m/ 03-图片截屏/ Created by Gavin on 15/9/14./ Copyright (c) 2015年 Gavin. All rights reserved./#import ViewController.hinterface ViewController ()/手指开始点property(nonatomic,assign)CGPoint startP;/遮

15、盖property(nonatomic,weak) UIView *coverView;property (weak, nonatomic) IBOutlet UIImageView *imageV;endimplementation ViewController/懒加载遮盖,保存遮盖只创建一次.-(UIView *)coverView if (_coverView = nil) UIView *view = UIView alloc init; view.backgroundColor = UIColor blackColor; view.alpha = 0.7; self.view add

16、Subview:view; _coverView = view; return _coverView;- (void)viewDidLoad super viewDidLoad; / Do any additional setup after loading the view, typically from a nib.- (IBAction)pan:(UIPanGestureRecognizer *)pan /获取当前手指所在的点. CGPoint curP = pan locationInView:self.view; if(pan.state = UIGestureRecognizerS

17、tateBegan) CGPoint startP = curP; self.startP = startP; else if(pan.state = UIGestureRecognizerStateChanged) CGFloat offsetX = curP.x - self.startP.x; CGFloat offsetY = curP.y - self.startP.y; /确定遮盖的区域位置 CGRect rect = CGRectMake(self.startP.x, self.startP.y, offsetX, offsetY); /每次移动时,调用遮盖的Frame. sel

18、f.coverView.frame = rect; else if(pan.state = UIGestureRecognizerStateEnded) /1.开启一个跟原始图片相同大小的图片上下文. UIGraphicsBeginImageContextWithOptions(self.imageV.bounds.size, NO, 0); /把self.cover.frame 设为裁剪区域 UIBezierPath *path = UIBezierPath bezierPathWithRect:self.coverView.frame; path addClip; /获取当前上下文. CG

19、ContextRef ctx = UIGraphicsGetCurrentContext(); /把UIImageView当中的图片给绘制上下文当中. self.imageV.layer renderInContext:ctx; /从上下文当中生成一张新的图片 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); /关闭上下文. UIGraphicsEndImageContext(); /给图片重新赋值 self.imageV.image = newImage; /移除遮盖 self.coverView removeF

20、romSuperview; - (void)didReceiveMemoryWarning super didReceiveMemoryWarning; / Dispose of any resources that can be recreated.end/ ViewController.m/ 04-图片擦除/ Created by Gavin on 15/9/14./ Copyright (c) 2015年 Gavin. All rights reserved./#import ViewController.hinterface ViewController ()property (wea

21、k, nonatomic) IBOutlet UIImageView *imageV;endimplementation ViewController- (void)viewDidLoad super viewDidLoad; / Do any additional setup after loading the view, typically from a nib. self.imageV.userInteractionEnabled = YES; /添加手势 UIPanGestureRecognizer *pan = UIPanGestureRecognizer alloc initWit

22、hTarget:self action:selector(pan:); self.imageV addGestureRecognizer:pan;- (void)pan:(UIPanGestureRecognizer *)pan /获取当前手指所在的点 CGPoint curP = pan locationInView:self.imageV; CGFloat rectWH = 50; CGFloat x = curP.x - rectWH * 0.5; CGFloat y = curP.y - rectWH * 0.5; CGRect rect = CGRectMake(x, y, rect

23、WH, rectWH); /开启一个图片上下文. UIGraphicsBeginImageContextWithOptions(self.imageV.bounds.size, NO, 0); /获取当前的上下文. CGContextRef ctx = UIGraphicsGetCurrentContext(); /把UImageViwe上面的图片给绘制到上下文. self.imageV.layer renderInContext:ctx; /确定擦除区域 CGContextClearRect(ctx, rect); /生成一张新图片 UIImage *newImage = UIGraphic

24、sGetImageFromCurrentImageContext(); /把上下文给关闭 UIGraphicsEndImageContext(); /给原来图片重新赋值 self.imageV.image = newImage; - (void)didReceiveMemoryWarning super didReceiveMemoryWarning; / Dispose of any resources that can be recreated.end/ ClockView.m/ 05-手势解锁/ Created by Gavin on 15/9/14./ Copyright (c) 20

25、15年 Gavin. All rights reserved./#import ClockView.himplementation ClockView-(void)awakeFromNib /添加按钮 self setUP;- (instancetype)initWithFrame:(CGRect)frame if (self = super initWithFrame:frame) /添加按钮 self setUP; return self;/添加按钮- (void)setUP for (int i = 0; i 9; i+) /创建按钮 UIButton *btn = UIButton b

26、uttonWithType:UIButtonTypeCustom; btn.userInteractionEnabled = NO; btn setImage:UIImage imageNamed:gesture_node_normal forState:UIControlStateNormal; btn setImage:UIImage imageNamed:gesture_node_highlighted forState:UIControlStateSelected; self addSubview:btn; /获取当前手指所在的点- (CGPoint)getCurrentPoint:(

27、NSSet *)touches /获取当前手指所在的点 UITouch *touch = touches anyObject; return touch locationInView:self;/判断当前手指在不在按钮上.- (UIButton *)btnRectContainsPoint:(CGPoint)point for (UIButton *btn in self.subviews) /判断当前手指在不在按钮上. /判断一个点在不在某个区域当中 if (CGRectContainsPoint(btn.frame, point) return btn; return nil; /手指开始

28、点击-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event NSLog(%s,_func_); CGPoint curP = self getCurrentPoint:touches; UIButton *btn = self btnRectContainsPoint:curP; if (btn) btn.selected = YES; /手指移动的时候调用-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event /获取当前手指所在的点 CGPoint

29、curP = self getCurrentPoint:touches; UIButton *btn = self btnRectContainsPoint:curP; if (btn) btn.selected = YES; /手指离开屏幕时调用- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event -(void)layoutSubviews super layoutSubviews; int clomn = 3; CGFloat x = 0; CGFloat y = 0; CGFloat btnWH = 74; CGFloat margin = (self.bounds.size.width - btnWH * cl

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1