ios8绘图方法小记touchesBegan&touchesMoved
2015-09-07 22:46
411 查看
// // 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) } }
相关文章推荐
- iOS开发 - 汉字转拼音
- IOS 中的页面跳转(navigaitonController)+带自动返回
- iOS开发:Delegate、Notification和KVO的联系与区别
- iOS开发:MVC(模型-视图-控制器)详解
- iOS编程:学习篇(十二)
- iOS数据持久化
- 新浪微博自定制TabBar
- IOS己见之NSDate
- iOS学习篇章3--SEL与@selector
- iOS 笔记六: 协议 Protocols
- IOS开发指南学习——数据持久化(Core Data)
- Installation Failure Troubleshooting for iOS
- 问题:In IOS8 wakeups limit
- iOS应用性能调优的25个建议和技巧
- IOS 技术进阶 —— RunLoop 原理和核心机制
- iOS中简单的KVC
- iOS开发系列课程(05) --- 导航视图控制器
- iOS学习篇章2--Category类别
- 小胖说事39-----iOS 获取通讯录中联系人的所有属性
- ios开发,javascript直接调用oc代码而非通过改变url回调方式