使用贝赛尔曲线画扇形、圆形、弧线、多边形,实现App下载时的动画效果demo
//
// MyView.swift
// TestUIBezierPath
//
// Created by iCodeWoods on 16/5/8.
// Copyright © 2016年 iCodeWoods. All rights reserved.
// import Foundation
import UIKit class MyView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.grayColor()
} required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
} // // 五边形
// override func drawRect(rect: CGRect) {
// let color = UIColor.redColor()
// color.set() // 设置线条颜色
//
// let aPath = UIBezierPath()
//
// aPath.lineWidth = 5.0 // 线条宽度
// aPath.lineCapStyle = .Round // 线条拐角
// aPath.lineJoinStyle = .Round // 终点处理
//
// // Set the starting point of the shape.
// aPath.moveToPoint(CGPointMake(100, 10))
//
// // Draw the lines
// aPath.addLineToPoint(CGPointMake(200, 50))
// aPath.addLineToPoint(CGPointMake(160, 150))
// aPath.addLineToPoint(CGPointMake(40, 140))
// aPath.addLineToPoint(CGPointMake(10, 60))
// aPath.closePath() // 最后一条线通过调用closePath方法得到
//
//// aPath.stroke() // Draws line 根据坐标点连线,不填充
// aPath.fill() // Draws line 根据坐标点连线,填充
// } // // 矩形
// override func drawRect(rect: CGRect) {
// let color = UIColor.redColor()
// color.set() // 设置线条颜色
//
// let aPath = UIBezierPath(rect: CGRectMake(40, 40, 100, 50)) // 长方形
//// let aPath = UIBezierPath(rect: CGRectMake(40, 40, 100, 100)) // 正方形
//
// aPath.lineWidth = 5.0 // 线条宽度
// aPath.lineCapStyle = .Round // 线条拐角
// aPath.lineJoinStyle = .Round // 终点处理
//
// aPath.stroke() // Draws line 根据坐标点连线,不填充
//// aPath.fill() // Draws line 根据坐标点连线,填充
// } // // 圆、椭圆
// override func drawRect(rect: CGRect) {
// let color = UIColor.redColor()
// color.set() // 设置线条颜色
//
// // 根据传人的矩形画出内切圆/椭圆
//// let aPath = UIBezierPath(ovalInRect: CGRectMake(40, 40, 100, 100)) // 如果传入的是正方形,画出的就是内切圆
// let aPath = UIBezierPath(ovalInRect: CGRectMake(40, 40, 100, 160)) // 如果传入的是长方形,画出的就是内切椭圆
//
// aPath.lineWidth = 5.0 // 线条宽度
//
//// aPath.stroke() // Draws line 根据坐标点连线,不填充
// aPath.fill() // Draws line 根据坐标点连线,填充
// } //// 弧线
// override func drawRect(rect: CGRect) {
// let color = UIColor.redColor()
// color.set() // 设置线条颜色
//
// let aPath = UIBezierPath(arcCenter: CGPointMake(150, 150), radius: 75, startAngle: 0, endAngle: (CGFloat)(90*M_PI/180), clockwise: true)
//
// aPath.lineWidth = 5.0 // 线条宽度
//
//// aPath.stroke() // Draws line 根据坐标点连线,不填充
// aPath.fill() // Draws line 根据坐标点连线,填充
// } // // 扇形
// override func drawRect(rect: CGRect) {
// let color = UIColor.redColor()
// color.set() // 设置线条颜色
//
// let aPath = UIBezierPath(arcCenter: CGPointMake(150, 150), radius: 75, startAngle: 0, endAngle: (CGFloat)(90*M_PI/180), clockwise: true)
// aPath.addLineToPoint(CGPointMake(150, 150))
// aPath.closePath()
// aPath.lineWidth = 5.0 // 线条宽度
//
// // aPath.stroke() // Draws line 根据坐标点连线,不填充
// aPath.fill() // Draws line 根据坐标点连线,填充
// } // 实现 App 下载时的效果
var beginAngle = M_PI*3/2 // 起点
var finishAngle = M_PI*3/2+M_PI*2/20 // 终点 override func drawRect(rect: CGRect) {
let color = UIColor.whiteColor()
color.set() // 设置线条颜色 let aPath = UIBezierPath(arcCenter: CGPointMake(150, 150), radius: 75, startAngle: (CGFloat)(beginAngle), endAngle: (CGFloat)(finishAngle), clockwise: true)
aPath.addLineToPoint(CGPointMake(150, 150))
aPath.closePath()
aPath.lineWidth = 5.0 // 线条宽度
// aPath.fill() // Draws line 根据坐标点连线,填充
aPath.fillWithBlendMode(.Normal, alpha: 0.5) finishAngle += M_PI/20 // 更新终点
}
}
使用贝赛尔曲线画扇形、圆形、弧线、多边形,实现App下载时的动画效果demo的更多相关文章
- Path画直线与弧线
代码地址如下:http://www.demodashi.com/demo/14754.html 前言 之前讲过Paint和Canvas的基本使用,今天来介绍下Path的使用 涉及内容有: Path画直 ...
- 纯CSS3画出小黄人并实现动画效果
前言 前两天我刚发布了一篇CSS3实现小黄人动画的博客,但是实现的CSS3动画是基于我在站酷网找到的一张小黄人的jpg格式图片,并自己用PS抠出需要实现动画的部分,最后才完成的动画效果.但是,其实我的 ...
- css画扇形按钮
最近项目中需要制作一个扇形按钮,效果是这样的: 周围四个扇形,和中间的小圆,全是能点击的.这就需要画扇形.百度了一下,有很多文章讲了如何生成扇形,最后我借鉴了一个最简单的实现方式,使用css的clip ...
- canvas画扇形图(本文来自于http://jo2.org/html5-canvas-sector/)
1.定义画扇形的构造函数: //扇形CanvasRenderingContext2D.prototype.sector = function (x, y, radius, sDeg, eDeg) {/ ...
- Python3 tkinter基础 Canvas create_rectangle 画虚边的矩形 create_oval 画椭圆形 圆形
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 根据多个点使用canvas贝赛尔曲线画一条平滑的曲线
众所周知想用canvas画一条曲线我们可以使用这些函数: 二次曲线:quadraticCurveTo(cp1x, cp1y, x, y) 贝塞尔曲线:bezierCurveTo(cp1x, cp1y, ...
- canvas画扇形、饼图
画扇形的方法 方法一:起始角度是0,那么第一条线就是line(r,0),通过旋转扇形的角度,第二条线就是line(r,0) //圆弧 ctx.save(); ctx.translate(100, 10 ...
- Android自定义View 画弧形,文字,并增加动画效果
一个简单的Android自定义View的demo,画弧形,文字,开启一个多线程更新ui界面,在子线程更新ui是不允许的,但是View提供了方法,让我们来了解下吧. 1.封装一个抽象的View类 B ...
- 纯css3圆形从中心向四周扩散动画效果
查看效果:http://hovertree.com/texiao/css3/37/ 先来个简单的示例,例如: @keyframes hovertreemove{from {top:30px;}to { ...
随机推荐
- 【Unity入门】碰撞检测与触发检测
版权声明:本文为博主原创文章,转载请注明出处. 在Unity里面,游戏物体的碰撞我们可以通过刚体组件(Rigidbody)和碰撞器组件(Collider)来进行检测.首先在场景里面添加一个Plane面 ...
- Chapter14:重载运算符
对于一个运算符函数来说,它或者是类的成员,或者至少含有一个类类型的参数. int operator+(int, int);//错误,不能为int重定义内置运算符 对于一个重载的运算符来说,其优先级和结 ...
- C++二叉树的实现
C++实现二叉查找树 啥是二叉查找树 在数据结构中,有一个奇葩的东西,说它奇葩,那是因为它重要,这就是树.而在树中,二叉树又是当中的贵族.二叉树的一个重要应用是它们在查找中的应用,于是就有了二叉查找树 ...
- Eclipse下建立geoserver源码工程
摘要:本文详细阐述,如何基于geoserver源码构建eclipse工程文件,操作过程中除用到jdk.eclipse以外,还有git和maven,操作系统为windows8. 1安装Git 从(htt ...
- IOS 异步加载图片
#import <Foundation/Foundation.h> #import "StringUtils.h" @interface ImageManager : ...
- home-brew 安装&下载
安装: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&qu ...
- mysql基础知识(3)--创建
创建表: 基本形式 create table [if not exists] 表名(字段列表, [约束或索引列表]) [表选项列表]; 说明:列表都是表示“多个”,相互之间用逗号分开. 字段基本 ...
- Improved logging in Objective-C
[Improved logging in Objective-C] Example of logging the current method and line number. Paste it in ...
- TdxAlertWindowManager右下角HINT显示控件
带爱像的右下角HINT显示,自动隐藏 function alterInfo: TdxAlertWindowManager;begin if not Assigned(Falter) then be ...
- HDU1712简单的分组背包
HDU1712http://acm.hdu.edu.cn/showproblem.php?pid=1712 简单的分组背包 #include <map> #include <set& ...