1
我在對齊UIView
和CAShapeLayer
時遇到問題。對齊UIView和CAShapeLayer的問題
下面是示例代碼演示該問題:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let square = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
square.transform = CGAffineTransformMakeRotation(CGFloat(20*M_PI/180))
square.backgroundColor = UIColor.grayColor()
view.addSubview(square)
let strokeLayer = CAShapeLayer()
strokeLayer.path = UIBezierPath(rect: square.bounds).CGPath
strokeLayer.position = square.center
strokeLayer.setAffineTransform(square.transform)
strokeLayer.fillColor = UIColor.clearColor().CGColor
strokeLayer.strokeColor = UIColor.redColor().CGColor
strokeLayer.lineWidth = 1
view.addSubview(square)
view.layer.addSublayer(strokeLayer)
}
}
下面是結果的圖像:
如何獲得兩個對齊?
沒有。看起來像這樣:http://imgur.com/YvHmZr8 – Trappar
也從您的形狀圖層中刪除變換 – nielsbot
http://imgur.com/qh8xrWH – Trappar