圖形內容相關的矩陣操作(平移-縮放-旋轉)

來源:互聯網
上載者:User

標籤:代碼   nbsp   swift   override   旋轉   graphics   lin   border   stroke   

圖形內容相關的矩陣操作(旋轉、縮放和平移)CGContextRotateCTM:圖形上下文旋轉,以內容相關的原點(左上方)為基準CGContextScaleCTM:圖形內容相關的縮放,以內容相關的原點(左上方)為基準CGContextTranslateCTM:圖形內容相關的平移,以內容相關的原(左上方)點為基準 注意:一定要在添加路徑之前進行設定 下面貼出swift版代碼:
 1 override func draw(_ rect: CGRect) { 2         let context = UIGraphicsGetCurrentContext() 3          4         // MARK: - 注意:矩陣操作一定要在添加路徑之前設定 5          6         // 旋轉 - 逆時針旋轉-M_PI_4(以原點為基準) 7         // context?.rotate(by: CGFloat(-M_PI_4)) 8          9         // 平移 - 往左下角(以原點為基準)10         // context?.translateBy(x: 50, y: 50)11         12         // 縮放 - 寬高各縮小一半(以原點為基準)13         context?.scaleBy(x: 0.5, y: 0.5)14         15         let borderPath = UIBezierPath(rect: rect)16         17         let rectPath = UIBezierPath(rect: CGRect(x: 10, y: 10, width: 200, height: 200))18         19         let circlePath = UIBezierPath(ovalIn: CGRect(x: 10, y: 210, width: 200, height: 200))20     21         context?.addPath(borderPath.cgPath)22         context?.addPath(rectPath.cgPath)23         context?.addPath(circlePath.cgPath)24         25         context?.setLineWidth(2)26         27         context?.strokePath()28     }

 

 

圖形內容相關的矩陣操作(平移-縮放-旋轉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.