swift - How to layout animations of sublayers of a CALayer -
i have layer sublayer. sublayer has position animated. want animation of position scale appropriately when bounds of superlayer change, e.g. width of superlayer doubles distance of animation doubles well.
i've been trying overriding superlayer's layoutsublayers() function , in replacing old animation new scaled one. adding new animation sublayer appears cause application window freeze application few seconds before starting animation switch fullscreen. other scaling of window works fine. following code using:
override func layoutsublayers() { guard self.image != nil else { return } if var currentposition = self.imagelayer.presentation()?.position { let relativecurrentposition = cgpoint(x: currentposition.x / self.oldbounds.width, y: currentposition.y / self.oldbounds.height) currentposition = cgpoint(x: self.bounds.width * relativecurrentposition.x, y: self.bounds.height * relativecurrentposition.y) var targetposition = (self.direction == .atob) ? self.positionb : self.positionb let relativetargetposition = cgpoint(x: targetposition.x / self.oldbounds.width, y: targetposition.y / self.oldbounds.height) targetposition = cgpoint(x: self.bounds.width * relativetargetposition.x, y: self.bounds.height * relativetargetposition.y) if self.direction == .atob { self.positiona = currentposition self.positionb = targetposition } else { self.positionb = currentposition self.positiona = targetposition } let newpananimation = self.pananimation newpananimation.duration = self.animationduration - (cacurrentmediatime() - self.timeatimagestart) self.imagelayer.add(newpananimation, forkey: "pan") } else { calayer.performwithoutanimation { self.imagelayer.position = cgpoint(x: self.bounds.width / 2, y: self.bounds.height / 2) } } calayer.performwithoutanimation { self.imagelayer.bounds = self.originalimagelayerbounds } } that why wondering, considered right way or if maybe on right track , there different issue.
thanks much!
Comments
Post a Comment