ios - 如何使用 pop 或 CoreAnimation 更改动画的起点或 anchor

标签 ios animation core-animation facebook-pop

下面的代码启动了一个缩放动画,它从 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/

相关文章:

javascript - Kinetic.js 在 Firefox 上运行缓慢

ios - 如果属性值匹配,UIView aniamteWithDuration 是否退出

iphone - UIView 3DCube 像 Clear-app

iphone - Fidget Spinner 动画 Swift?

iphone - UITableViewRowAnimationFade 不工作

ios - 无法在Swift中设置IndexPath行

javascript - JavaScript 中的动画与模数

Objective-C - CABasicAnimation 在动画后应用更改?

ios - 奇怪的 Swift XCode 'Undefined Symbols' 错误

ios - 请求被服务委托(delegate) (SBMainWorkspace) 拒绝