スタート...私はそれをどのように作成するかに関係なく、「開始」ポイントは「右側に常にあるようですあなたが欲しい開始角度その後、あなたの矩形に内接する楕円形にその円を変換
extension UIBezierPath {
convenience init(ovalInRect rect: CGRect, startAngle: CGFloat, clockwise: Bool) {
self.init()
// Create a circle at the origin with diameter 1.
addArcWithCenter(.zero, radius: 0.5, startAngle: startAngle, endAngle: startAngle + 2 * CGFloat(M_PI), clockwise: clockwise)
closePath()
// Construct a transform that moves the circle to inscribe `rect`.
var transform = CGAffineTransformIdentity
// This part moves the center of the circle to the center of `rect`.
transform = CGAffineTransformTranslate(transform, rect.midX, rect.midY)
// This part scales the circle to an oval with the same width and height as `rect`.
transform = CGAffineTransformScale(transform, rect.width, rect.height)
applyTransform(transform)
}
}
使用例:。。
let oval = UIBezierPath(ovalInRect: CGRectMake(50, 20, 100, 200), startAngle: CGFloat(-M_PI), clockwise: true)
Swift.print(oval.bounds)
出力:半径::startAngleの:endAngle:時計回り: `あなたが-M_PI``からM_PI` `に行くので、もし、あなたが、それを開始と終了を制御することができます
(50.0, 20.0, 100.0, 200.0)
あなたは' bezierPathWithArcCenterを使用している場合左から始まります。しかしそれは確かにサークルです。左から楕円が必要な場合は、独自の 'UIBezierPath'を定義するか、このルーチンを使用する必要がありますが、ビュー/レイヤーを変換してそれを反転させる必要があります。 – Rob
私はこれを試しましたが、何もしません... mirrorXorigin = CGAffineTransformMakeScale(-1.0,1.0) ovalPath.applyTransform(mirrorXorigin) –
shapeLayerにapplyTransformがありません –