Ios UIView.animate结束后代码不执行?
我在Ios UIView.animate结束后代码不执行?,ios,swift,animation,uiview,uiviewanimation,Ios,Swift,Animation,Uiview,Uiviewanimation,我在ui视图的draw功能中。 我想画一个三角形,然后在动画之后,它是一个镜像副本。 我可以绘制三角形和动画,或者三角形和它的副本,但是当我在动画的“完成”部分添加用于绘制副本的代码时,它不会被绘制。 我不知道如何解决这个问题 这是我的代码(镜像副本的图纸没有显示任何内容) (不是专家)但我不建议在draw功能中使用truing来制作动画,而是使用draw来绘制您想要呈现的状态,并animate在这些状态之间移动。我的“假设”是,当调用完成块调用sv.layoutIfNeeded()以在视图动画
ui视图的draw
功能中。
我想画一个三角形,然后在动画之后,它是一个镜像副本。
我可以绘制三角形和动画,或者三角形和它的副本,但是当我在动画的“完成”部分添加用于绘制副本的代码时,它不会被绘制。
我不知道如何解决这个问题
这是我的代码(镜像副本的图纸没有显示任何内容)
(不是专家)但我不建议在draw
功能中使用truing来制作动画,而是使用draw
来绘制您想要呈现的状态,并animate
在这些状态之间移动。我的“假设”是,当调用完成块调用sv.layoutIfNeeded()以在视图动画方法中重新加载视图时,上下文
不再有效。这不是动画的问题,有了这段代码,动画就像一个符咒,它只是“finish in”中的上下文。*
方法“对于不产生任何视觉效果的动画…(不是专家),但我不建议在draw
功能中使用truing来制作动画,而是使用draw
来绘制要呈现的状态,并在这些状态之间移动animate
。我的“假设”是,当调用完成块调用sv.layoutIfNeeded()以在视图动画方法中重新加载视图时,上下文
不再有效。这不是动画的问题,有了这段代码,动画就像一个符咒,它只是“finish in”中的上下文。*
方法“的动画,它不会产生任何视觉效果。。。
public override func draw(_ rect: CGRect) {
guard let context = UIGraphicsGetCurrentContext() else { return }
let viewWidth = self.bounds.width
let viewHeight = self.bounds.height
context.setLineWidth(1.0)
context.setStrokeColor(UIColor.darkGray.cgColor)
context.beginPath()
let path = CGMutablePath()
let r = sqrt(viewHeight * viewHeight + viewWidth * viewWidth) * 0.50
let p1 = CGPoint(x: viewWidth/2, y: 20 + r)
var angle = CGFloat.pi * (90.0 + 30.0) / 180.0
let p2 = CGPoint(x: p1.x + cos(angle) * r, y: p1.y - sin(angle) * r)
angle = CGFloat.pi * 90.0 / 180.0
let p3 = CGPoint(x: p1.x + cos(angle) * r, y: p1.y - sin(angle) * r)
path.move(to: p1)
path.addLine(to: p2)
path.addLine(to: p3)
path.closeSubpath()
context.addPath(path)
context.strokePath()
let trf = CGAffineTransform(scaleX: -1, y: 1)
let sv = UIView(frame:self.bounds)
self.addSubview(sv)
let shapeLayer = CAShapeLayer.init()
shapeLayer.path = path
shapeLayer.strokeColor = UIColor.red.cgColor
shapeLayer.lineWidth = 1.0
sv.layer.addSublayer(shapeLayer)
shapeLayer.display()
UIView.animate(withDuration: 0.5, delay: 0, options: [],
animations: {
sv.transform = trf
}) { finished in
sv.removeFromSuperview()
context.setStrokeColor(UIColor.red.cgColor)
context.scaleBy(x: -1, y: 1)
context.translateBy(x:-viewWidth, y:0)
context.addPath(path)
context.strokePath()
context.scaleBy(x: -1, y: 1)
context.translateBy(x:viewWidth, y:0)
}
}