0
私はあなたがタップできるUIImageViewを持っていて、それは円を描画しています。私は、円の位置を辞書の配列に格納します。これにより、サークルの描画を「再生」することができます。ただし、UIImageViewが元のサイズと異なる場合、円は新しいUIImageViewに比例しません。CAShapeLayerを別のUIImageViewに合わせる方法
どのようにして円を拡大縮小できますか?デモンストレーションの目的のために、一番上のピクチャは、入力に使用されるUIImageViewのサイズであり、二番目は再生用のサイズです。
入力環境サークル:
リプレイ円は(円は青色UIImageViewでなければならない私はCATransform3DMakeScale
としてでこの問題を解決することができた
import Foundation
import UIKit
class DrawPuck {
func drawPuck(circle: CGPoint, circleColour: CGColor, circleSize: CGFloat, imageView: UIImageView) {
let circleBezierPath = UIBezierPath(arcCenter: CGPoint(x: circle.x,y: circle.y), radius: CGFloat(circleSize), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circleBezierPath.cgPath
//change the fill color
shapeLayer.fillColor = circleColour
//you can change the stroke color
shapeLayer.strokeColor = UIColor.white.cgColor
//you can change the line width
shapeLayer.lineWidth = 0.5
imageView.layer.addSublayer(shapeLayer)
}
}