我正在尝试为按钮设置动画.按钮将以0的高度和宽度开始,并扩展到其预期大小的100%.然后它将缩小到其尺寸的80%,然后再次回升到100%.
有没有办法做到这一点,而无需为每个位置明确计算CGRect?问题是当在80%时框架与框架的位置不完全对齐在100%.我必须手动计算帧的x和y位置,这是非常耗时的,因为我正在为很多按钮执行此操作.
这是我目前正在尝试做的事情:
CGRect smallPlay = CGRectMake(PlayButton.frame.origin.x + 94, PlayButton.frame.origin.y + 23, 0, 0);
CGRect almostFullPlay = CGRectMake(40, 170, 160, 30);
[UIView animateWithDuration:0.3
delay:0
options: UIViewAnimationCurveEaseOut
animations:^{
PlayButton.frame = smallPlay;
PlayButton.frame = CGRectMake(50, 178, 187, 45);
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.2
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
PlayButton.frame = almostFullPlay;
PlayButton.frame = CGRectMake(50, 178,187, 45);
} completion:^(BOOL finished){
NSLog(@"Done!");
}
];
}];
Run Code Online (Sandbox Code Playgroud)
编辑:我意识到我可以写一个函数来计算80%的帧,但我想知道是否有更好的方法来做这个不需要我写任何额外的东西.