運用 UIBezierPath繪製不同的形狀

雖然彼得潘要我們繪出可愛的圖案,但是我還是決定要搭上時事,離復仇者聯盟四:終局之戰剩下不到一個月的時間,我就決定畫一個A吧。
是的,就是一個A而已,很快速地只使用幾個UIBezierPath連一連就結束啦。(其實事情不是這麼簡單的。

我拉這個圖案真的是拉了真他M的久,直接看看圖片,看我的成果如何。

是不是很不錯啊?果然沒有辜負認真上彼得潘的課這樣子。

發文的時間還在愚人節,沒事兒沒事兒。
下面這個才是我自己繪製的啦~~~

其實個人覺得已經有一個87分像了啦,只是那個圓形,真的是很難處理。
在那邊對老半天,起始角度、終止角度、點的連結、點的位置,真的都是要一點一點的在那邊對。
我能用Swift做出這樣的成果我已經感覺到滿意了。

下面就是我的程式碼的部分,上面我也有註解那段是那個部分,大家可以參考看看。

import UIKitlet path = UIBezierPath()//draw Apath.move(to: CGPoint(x:340, y:15))path.addLine(to: CGPoint(x:414, y:15))path.addLine(to: CGPoint(x: 418, y: 380))path.addLine(to: CGPoint(x: 339, y: 295))path.addLine(to: CGPoint(x: 339, y: 178))path.addLine(to: CGPoint(x: 260, y: 348))path.addLine(to: CGPoint(x: 340, y: 348))path.addLine(to: CGPoint(x: 340, y: 311))path.addLine(to: CGPoint(x: 414, y: 390))path.addLine(to: CGPoint(x: 340, y: 450))path.addLine(to: CGPoint(x: 340, y: 420))path.addLine(to: CGPoint(x: 235, y: 420))path.addLine(to: CGPoint(x: 152, y: 588))path.addLine(to: CGPoint(x: 63, y: 588))path.close()//draw trianglepath.move(to: CGPoint(x: 420, y: 400))path.addLine(to: CGPoint(x: 422, y: 465))path.addLine(to: CGPoint(x: 340, y: 465))path.close()//draw circlelet aDegree = CGFloat.pi/180path.move(to: CGPoint(x: 452, y: 66))path.addArc(withCenter: CGPoint(x: 315, y: 310), radius: 280, startAngle: aDegree*300, endAngle: aDegree*118, clockwise: true)path.addLine(to: CGPoint(x: 206, y: 526))path.addArc(withCenter: CGPoint(x: 315, y: 310), radius: 240, startAngle: aDegree*116, endAngle: aDegree*302, clockwise: false)path.close()path.move(to: CGPoint(x: 310, y: 35))path.addArc(withCenter: CGPoint(x: 315, y: 310), radius: 280, startAngle: aDegree*269.6, endAngle: aDegree*141, clockwise: false)path.addLine(to: CGPoint(x: 113, y: 462.5))path.addArc(withCenter: CGPoint(x: 315, y: 310), radius: 240, startAngle: aDegree*144.2, endAngle: aDegree*265, clockwise: true)path.close()
let AvengersLayer = CAShapeLayer()AvengersLayer.path = path.cgPathlet AvengersView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 1000))AvengersView.backgroundColor = UIColor(red: 0.63, green: 0.66, blue: 0.564, alpha: 1)AvengersView.layer.mask = AvengersLayerAvengersView

文末工商服務一下,如果你還不是漫威迷,或者是想要當個一日漫威迷看看復仇者聯盟End Game到底在演什麼東西,那麼!底下的這個連結你一定要全部看完,這個是臨時抱佛腳最有用的方式喔。
全部看完之後到這個月底上映的時候,看過的人一定可以馬上地進入劇情啦!!!

--

--