2017-02-23 4 views
0

私はあなたがタップできるUIImageViewを持っていて、それは円を描画しています。私は、円の位置を辞書の配列に格納します。これにより、サークルの描画を「再生」することができます。ただし、UIImageViewが元のサイズと異なる場合、円は新しいUIImageViewに比例しません。CAShapeLayerを別のUIImageViewに合わせる方法

どのようにして円を拡大縮小できますか?デモンストレーションの目的のために、一番上のピクチャは、入力に使用されるUIImageViewのサイズであり、二番目は再生用のサイズです。

入力環境サークル:

enter image description here

リプレイ円は(円は青色UIImageViewでなければならない私はCATransform3DMakeScaleとしてでこの問題を解決することができた

enter image description here

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) 

    } 

} 

答えて

0

私は元の画像の元のアスペクト比を維持する限り、それは素晴らしい作品です。

let width = yellowImageView.frame.width/blueImageView.frame.width 
    let height = yellowImageView.frame.height/blueImageView.frame.height 

    shapeLayer.transform = CATransform3DMakeScale(height, width, 1.0) 

    view.layer.addSublayer(shapeLayer) 
関連する問題