zoukankan      html  css  js  c++  java
  • 使用贝赛尔曲线画扇形、圆形、弧线、多边形,实现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 // 更新终点
        }
    }
    
  • 相关阅读:
    如何优雅地用Redis实现分布式锁?
    redis 持久化有几种方式?
    怎么保证缓存和数据库数据的一致性?
    jedis 和 redisson 有哪些区别?
    redis支持哪些数据类型?redis命令大全
    什么是redis的缓存雪崩与缓存穿透?如何解决?
    redis 为什么是单线程的?
    什么是memecache?redis 和 memecache 有什么区别?
    Redis入门到精通(九)——Redis数据库基本操作(切换数据库,数据移动,删除数据)
    Redis入门到精通(八)——key通用指令基本操作、key扩展操作(时效性控制、查询模式)、key其他操作(为key改名)
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/5960364.html
Copyright © 2011-2022 走看看