我正在使用 UIBezierPath 在 UIView 上绘制椭圆形InRect,它工作正常,但是当我在更改椭圆形InRect后移动 UIView 时, UIView 采用旧位置而不更改 UIView 位置。
ellipsePath = UIBezierPath(ovalInRect: CGRectMake(0, 0, radiusValue , radiusValue))
shapeLayer.path = ellipsePath.CGPath
shapeLayer.fillColor = UIColor.clearColor().CGColor
shapeLayer.strokeColor = UIColor.blueColor().CGColor
shapeLayer.lineWidth = 1
shapeLayer.sublayers?.removeAll()
moveView.layer.addSublayer(shapeLayer)
现在我在 moveView 上得到了椭圆形InRect 现在我使用UIPanGestureRecognizer旧位置将屏幕上的 moveView 移动到任何其他位置
func recognizePanGesture(sender: UIPanGestureRecognizer)
{
let translate = sender.translationInView(self.view)
sender.view!.center = CGPoint(x:sender.view!.center.x + translate.x,
y:sender.view!.center.y + translate.y)
sender.setTranslation(CGPointZero, inView: self.view)
}
然后在我更新ovalInRect之后
ellipsePath.removeAllPoints()
let tempPath = CGPathCreateMutableCopy(ellipsePath.CGPath)
CGPathAddEllipseInRect(tempPath, nil, CGRectMake(0
,0, topA , rightB))
ellipsePath.CGPath = tempPath!
shapeLayer.path = ellipsePath.CGPath
shapeLayer.sublayers?.removeAll()
moveView.layer.addSublayer(shapeLayer)
moveView 自动移动到旧位置(ovalInRect 工作正常)。
当我更新椭圆形矩形时间时,我不想改变位置。