ios8绘图方法小记touchesBegan&touchesMoved

ios8绘图方法小记touchesBegan&touchesMoved////MyView.swift//L01Test////Createdbyrobertkunon15/9/7.//Copyright(c)2015MAC.Allrightsreserved.//importUIKitclassMyView:UIView{varpath=CGPathCreateMutable()//On

//
//  MyView.swift
//  L01Test
//
//  Created by robertkun on 15/9/7.
//  Copyright (c) 2015 MAC. All rights reserved.
//

import UIKit
 class MyView: UIView { var path = CGPathCreateMutable() // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func drawRect(rect: CGRect) { // Drawing code UIColor.redColor().set() var context = UIGraphicsGetCurrentContext() CGContextSetLineWidth(context, 5) CGContextAddPath(context, path) CGContextStrokePath(context) } override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { let p = (touches as NSSet).anyObject()?.locationInView(self) CGPathMoveToPoint(path, nil, p!.x, p!.y) } override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) { let p = (touches as NSSet).anyObject()?.locationInView(self) CGPathAddLineToPoint(path, nil, p!.x, p!.y) setNeedsDisplay() } func drawTwoLines(point:CGPoint, lineJoin:CGLineJoin) { let context = UIGraphicsGetCurrentContext() CGContextSetLineJoin(context, lineJoin) CGContextSetLineWidth(context, 5) CGContextMoveToPoint(context, point.x-100, point.y+50) CGContextAddLineToPoint(context, point.x, point.y) CGContextAddLineToPoint(context, point.x+100, point.y+50) CGContextStrokePath(context) } } 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/39307.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注