mirror of
https://github.com/exyte/Macaw.git
synced 2024-10-26 13:01:25 +03:00
Add correct zoom-scroll handling
This commit is contained in:
parent
4d630c7586
commit
d9a5b27e94
@ -13,6 +13,9 @@ class AnimationsHierarchyViewController: UIViewController {
|
||||
|
||||
@IBOutlet weak var animView: MacawView!
|
||||
|
||||
var startCallbacks: [()->()] = []
|
||||
var stopCallbacks: [()->()] = []
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
@ -20,6 +23,22 @@ class AnimationsHierarchyViewController: UIViewController {
|
||||
animView.zoom.enable()
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
startCallbacks.forEach {
|
||||
$0()
|
||||
}
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
|
||||
stopCallbacks.forEach {
|
||||
$0()
|
||||
}
|
||||
}
|
||||
|
||||
func createTree(height: Int) -> Node {
|
||||
let rect = Rect(w: 10, h: 10)
|
||||
|
||||
@ -52,7 +71,14 @@ class AnimationsHierarchyViewController: UIViewController {
|
||||
func createLeaf(childForm: Locus, xDelta: Double, yDelta: Double) -> Group {
|
||||
let inset = childForm.bounds().w / 2
|
||||
let leaf = Shape(form: childForm, fill: Color.teal, place: .move(dx: -inset, dy: -inset))
|
||||
leaf.placeVar.animation(angle: 2 * .pi, during: 5).cycle().play()
|
||||
|
||||
let animation = leaf.placeVar.animation(angle: 2 * .pi, during: 5).cycle()
|
||||
startCallbacks.append({
|
||||
animation.play()
|
||||
})
|
||||
stopCallbacks.append({
|
||||
animation.stop()
|
||||
})
|
||||
|
||||
let leafGroup = [leaf].group(place: .move(dx: xDelta, dy: yDelta))
|
||||
leaf.onTap { _ in
|
||||
|
@ -8,7 +8,7 @@ import AppKit
|
||||
|
||||
class AnimationUtils {
|
||||
|
||||
class func layerForNodeRenderer(_ renderer: NodeRenderer, _ context: AnimationContext, animation: Animation, customBounds: Rect? = .none, shouldRenderContent: Bool = true) -> ShapeLayer {
|
||||
class func layerForNodeRenderer(_ renderer: NodeRenderer, animation: Animation, customBounds: Rect? = .none, shouldRenderContent: Bool = true) -> ShapeLayer {
|
||||
|
||||
let node = renderer.node
|
||||
if let cachedLayer = renderer.layer {
|
||||
|
@ -30,7 +30,7 @@ func addMorphingAnimation(_ animation: BasicAnimation, _ context: AnimationConte
|
||||
let toLocus = morphingAnimation.getVFunc()(animation.autoreverses ? 0.5 : 1.0)
|
||||
let duration = animation.autoreverses ? animation.getDuration() / 2.0 : animation.getDuration()
|
||||
|
||||
let layer = AnimationUtils.layerForNodeRenderer(renderer, context, animation: animation, shouldRenderContent: false)
|
||||
let layer = AnimationUtils.layerForNodeRenderer(renderer, animation: animation, shouldRenderContent: false)
|
||||
|
||||
// Creating proper animation
|
||||
let generatedAnimation = pathAnimation(
|
||||
|
@ -58,7 +58,7 @@ func addOpacityAnimation(_ animation: BasicAnimation, _ context: AnimationContex
|
||||
completion()
|
||||
}
|
||||
|
||||
let layer = AnimationUtils.layerForNodeRenderer(renderer, context, animation: animation)
|
||||
let layer = AnimationUtils.layerForNodeRenderer(renderer, animation: animation)
|
||||
let animationId = animation.ID
|
||||
layer.add(generatedAnimation, forKey: animationId)
|
||||
animation.removeFunc = { [weak layer] in
|
||||
|
@ -30,7 +30,7 @@ func addShapeAnimation(_ animation: BasicAnimation, _ context: AnimationContext,
|
||||
let toShape = shapeAnimation.getVFunc()(animation.autoreverses ? 0.5 : 1.0)
|
||||
let duration = animation.autoreverses ? animation.getDuration() / 2.0 : animation.getDuration()
|
||||
|
||||
let layer = AnimationUtils.layerForNodeRenderer(renderer, context, animation: animation, shouldRenderContent: false)
|
||||
let layer = AnimationUtils.layerForNodeRenderer(renderer, animation: animation, shouldRenderContent: false)
|
||||
|
||||
// Creating proper animation
|
||||
let generatedAnimation = generateShapeAnimation(context,
|
||||
|
@ -22,7 +22,7 @@ func addTransformAnimation(_ animation: BasicAnimation, _ context: AnimationCont
|
||||
let transactionsDisabled = CATransaction.disableActions()
|
||||
CATransaction.setDisableActions(true)
|
||||
|
||||
let layer = AnimationUtils.layerForNodeRenderer(renderer, context, animation: animation, shouldRenderContent: true)
|
||||
let layer = AnimationUtils.layerForNodeRenderer(renderer, animation: animation, shouldRenderContent: true)
|
||||
|
||||
// Creating proper animation
|
||||
let generatedAnimation = transformAnimationByFunc(transformAnimation,
|
||||
|
@ -142,8 +142,14 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
||||
}
|
||||
|
||||
private func onZoomChange(t: Transform) {
|
||||
// TODO: actually we should track all changes
|
||||
placeManager.setZoom(place: t)
|
||||
self.setNeedsDisplay()
|
||||
placeManager.setLayout(place: layoutHelper.getTransform(renderer!, contentLayout, bounds.size.toMacaw()))
|
||||
|
||||
if let viewLayer = mLayer {
|
||||
let deltaTransform = CATransform3DMakeAffineTransform(self.place.toCG())
|
||||
viewLayer.transform = CATransform3DConcat(viewLayer.transform, deltaTransform)
|
||||
}
|
||||
}
|
||||
|
||||
func initializeView() {
|
||||
@ -195,11 +201,6 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
||||
return
|
||||
}
|
||||
renderer.calculateZPositionRecursively()
|
||||
|
||||
// TODO: actually we should track all changes
|
||||
placeManager.setLayout(place: layoutHelper.getTransform(renderer, contentLayout, bounds.size.toMacaw()))
|
||||
|
||||
ctx.concatenate(self.place.toCG())
|
||||
renderer.render(in: ctx, force: false, opacity: node.opacity)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user