首页 技术 正文
技术 2022年11月13日
0 收藏 620 点赞 3,980 浏览 2901 个字

#import “ViewController.h”

#import “DrawView.h”

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

– (IBAction)doTouchButton:(id)sender;

@end

@implementation ViewController

– (void)viewDidLoad {

[super viewDidLoad];

DrawView *view=[[DrawView alloc]initWithFrame:self.view.frame];

view.backgroundColor =[UIColor whiteColor];

//    [self.view addSubview:view];//去掉注释后,显示绘图

}

– (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

– (IBAction)doTouchButton:(id)sender {

//小鸡走五角星

CGMutablePathRef startPath=CGPathCreateMutable();//创建一个路径

CGPathMoveToPoint(startPath, NULL, 160, 100);

CGPathAddLineToPoint(startPath, NULL, 220, 280);

CGPathAddLineToPoint(startPath, NULL, 60, 170);

CGPathAddLineToPoint(startPath, NULL, 260, 170);

CGPathAddLineToPoint(startPath, NULL, 100, 280);

CGPathAddLineToPoint(startPath, NULL, 160, 100);

CAKeyframeAnimation *animation=[CAKeyframeAnimation  animationWithKeyPath:@”position”];

animation.duration=5.0;//设置动画时间

[animation setPath:startPath];//设置路径

[_imageView.layer addAnimation:animation forKey:@”position”];

}

@end

/********************************************************/

//

//  DrawView.h

//  IOS绘图0817

//

//  Created by 张艳锋 on 15/8/17.

//  Copyright (c) 2015年 张艳锋. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface DrawView : UIView

@end

/********************************************************/

//

#import “DrawView.h”

@implementation DrawView

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

– (void)drawRect:(CGRect)rect {

// Drawing code

CGContextRef context=UIGraphicsGetCurrentContext();//绘制图形上下文

CGContextSetLineWidth(context, 2.0);//设直线条宽度

[[UIColor redColor]setStroke];//设置线条颜色

CGPoint point1=CGPointMake(160, 100);//上

CGPoint point2=CGPointMake(60, 170);//左

CGPoint point3=CGPointMake(260, 170);//右

CGPoint point4=CGPointMake(100, 280);//下左

CGPoint point5=CGPointMake(220, 280);//下右

CGContextMoveToPoint(context, point1.x, point1.y);

CGContextAddLineToPoint(context, point5.x, point5.y);

CGContextAddLineToPoint(context, point2.x, point2.y);

CGContextAddLineToPoint(context, point3.x, point3.y);

CGContextAddLineToPoint(context, point4.x, point4.y);

//    CGContextAddLineToPoint(context, point1.x, point1.y);

CGContextClosePath(context);//闭合区域函数

//    CGContextStrokePath(context);

[[UIColor orangeColor]setFill];//设置填充颜色

CGContextDrawPath(context, kCGPathFillStroke);//进行描绘函数

//    kCGPathFill,//无边线,包围区域全部填充

//    kCGPathEOFill,//无边线,包围区域重合部分不填充

//    kCGPathStroke,//只显边线,不填充

//    kCGPathFillStroke,//填充又显示边线

//    kCGPathEOFillStroke//有边线包围区域重合部分不填充

//正方形

//CGContextAddRect矩形

//CGContextAddEllipseInRect椭圆 圆

CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);//红色

CGContextSetLineWidth(context, 1.5);

CGContextAddRect(context, CGRectMake(100, 60, 80, 80));//正方形

CGContextAddRect(context, CGRectMake(200, 60, 100, 200));//矩形

CGContextAddEllipseInRect(context,CGRectMake(50, 100, 100, 60));//椭圆

CGContextAddEllipseInRect(context,CGRectMake(50, 200, 100, 100));//圆

CGContextStrokePath(context);

}

IOS绘图

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857