下面的代码启动了一个缩放动画,它从 UIButton
的中心沿着 XY 展开。如何让它从左边开始或 frame.origin.x = 0
POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
anim.fromValue = [NSValue valueWithCGRect:CGRectMake(signupButton.frame.origin.x,
signupButton.frame.origin.y,
0,
signupButton.frame.size.height)];
anim.toValue = [NSValue valueWithCGRect:signupButton.frame];
[anim setValue:@"progressBar" forKey:@"animName"];
anim.delegate = self;
// I tried to set anchor point but without any luck
// signupButton.layer.anchorPoint = CGPointMake(150, signupButton.frame.origin.y);
[signupButton.layer pop_addAnimation:anim forKey:@"signupButton"];
最佳答案
您正在为边界设置动画,但在框架中传递。您想要为边界设置动画是正确的。
所以,我认为这是正确的代码。
POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
CGRect startRect = signupButton.layer.bounds;
startRect.size.width = 0.0;
anim.fromValue = [NSValue valueWithCGRect:startRect];
anim.toValue = [NSValue valueWithCGRect:signupButton.layer.bounds];
[anim setValue:@"progressBar" forKey:@"animName"];
anim.delegate = self;
//anchor on the center left
CGPoint center = signupButton.layer.position;
signupButton.layer.anchorPoint = CGPointMake(0, 0.5);
signupButton.layer.position = CGPointMake(center.x - signupButton.layer.bounds.size.width * 0.5, center.y);
[signupButton.layer pop_addAnimation:anim forKey:@"signupButton"];
关于ios - 如何使用 pop 或 CoreAnimation 更改动画的起点或 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29773487/