ios - How to prevent CABasicAnimation from scale all content inside UIView? -
i've wrote apply heart beat animation cashapelayer, after worked fine, need implement behind uibutton (btntest) without scaling uibutton or other content.
@iboutlet weak var btntest: uibutton! let btnlayer = cashapelayer() override func viewdidload() { super.viewdidload() } override func viewdidappear(_ animated: bool) { super.viewdidappear(animated) btntest.layer.removeallanimations() let ovalpath = uibezierpath(arccenter: cgpoint(x: btntest.frame.midx, y: btntest.frame.midy), radius: 100, startangle: 0*(cgfloat.pi / 180), endangle: 360*(cgfloat.pi / 180), clockwise: true) btnlayer.path = ovalpath.cgpath btnlayer.fillcolor = uicolor.red.cgcolor btnlayer.contentsgravity = "center" btnlayer.opacity = 0.3 self.view.layer.addsublayer(btnlayer) let theanimation = cabasicanimation(keypath: "transform.scale.xy") theanimation.duration = 0.75 theanimation.repeatcount = float.infinity theanimation.autoreverses = true theanimation.fromvalue = 1.0 theanimation.tovalue = 1.2 theanimation.timingfunction = camediatimingfunction(name: kcamediatimingfunctioneasein) self.view.layer.add(theanimation, forkey: nil) }
the result gif
another solution changing line :
self.view.layer.add(theanimation, forkey: nil)
to :
btnlayer.add(theanimation, forkey: nil)
the result of this :gif
any ideas solve problem !
you want animate btnlayer
. reason it's animating wrong place layer's anchorpoint
@ 0,0, should set 0.5, 0.5.
edit:
actually, think issue put btnlayer
. should make sublayer of button view's layer, , give frame that's bounds of button's layer:
btntest.layer.addsublayer(btnlayer) btnlayer.frame = btntest.layer.bounds
Comments
Post a Comment