//
// 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)
}
}
ios8绘图方法小记touchesBegan&touchesMoved
最新推荐文章于 2022-01-04 14:08:20 发布