Last active
July 3, 2024 16:46
-
-
Save maxcampolo/45383dd542a68090cc63f7be18d993ae to your computer and use it in GitHub Desktop.
Animate position of a sublayer when animating a UIView.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override func layoutSubviews() { | |
super.layoutSubviews() | |
// If the view is animating apply the animation to the sublayer | |
CATransaction.begin() | |
if let animation = layer.animationForKey("position") { | |
CATransaction.setAnimationDuration(animation.duration) | |
CATransaction.setAnimationTimingFunction(animation.timingFunction) | |
} else { | |
CATransaction.disableActions() | |
} | |
if mySubLayer.superlayer == layer { | |
mySubLayer.frame = bounds | |
} | |
CATransaction.commit() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment