我希望在它所在的位置重新调整按钮大小并延迟它,你能帮助我吗? (发件人=的UIButton)
我的功能:
-(IBAction)Animate: (id) sender
{
[sender setBackgroundImage:[UIImage imageNamed:@"Text Bg large.png"] forState:UIControlStateNormal];
CABasicAnimation *scale;
scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scale.fromValue = [NSNumber numberWithFloat:1];
scale.toValue = [NSNumber numberWithFloat:1.3];
scale.duration = 1;
scale.removedOnCompletion = NO;
scale.repeatCount = 1;
[sender addAnimation:scale forKey:@""];
[sender setFrame:(CGRectMake(x, y, z, w))];
}
如果我希望该按钮保持在同一位置,并且在不手动输入值的情况下增大1.3倍,我会对x,y,z,w使用什么?哦,我怎么能延迟这个操作呢?
答案 0 :(得分:2)
您是否有任何理由使用CAAnimation
来执行此操作?
怎么样:
CGRect newFrame = CGRectInset(sender.frame, CGRectGetWidth(sender.frame) * -0.15, CGRectGetHeight(sender.frame) * -0.15);
[UIView animateWithDuration: 1.0
delay: 0.5
options: UIViewAnimationOptionCurveLinear
animations:^{
[sender setFrame: newFrame];
}
completion: nil];
或
[UIView animateWithDuration: 1.0
delay: 0.5
options: UIViewAnimationOptionCurveLinear
animations:^{
[sender setTransform: CGAffineTransformMakeScale(1.3, 1.3)];
}
completion: nil];
答案 1 :(得分:0)
这样做:
-(IBAction)Animate:(id) sender
{
UIButton *btnAnimate = (UIButton *)sender;
btnAnimate.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
btnAnimate.transform = CGAffineTransformMakeScale(1.3f, 1.3f);
} completion:^(BOOL finished){
[btnAnimate setFrame:(CGRectMake(x, y, z, w))];
}];
}