【问题标题】:Objective C Button resize and delayObjective C 按钮调整大小和延迟
【发布时间】:2012-09-05 08:23:47
【问题描述】:

我想在它所在的地方重新调整按钮的大小并延迟它,你能帮我吗? (发件人=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 使用什么。哦,我怎么能延迟这个操作?

【问题讨论】:

  • 动画已经放大了1.3倍,不是吗?您到底想在这里做什么,什么不起作用?
  • 是的,动画正在缩放它。但是动画结束后它会缩小到原始大小,我希望在动画结束后将其修复为新的大小。
  • 啊,对,明白了。我的核心动画生锈了:)

标签: objective-c ios xcode


【解决方案1】:

您使用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];

【讨论】:

    【解决方案2】:

    这样做:

    -(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))];
    
      }];
    }
    

    【讨论】:

    • 谢谢,但我如何设置新位置?
    • 动画后,CGRectMake(x, y, z, w) 发生。我需要输入一些值而不是 x,y,z,w。我不想以 CGRectMake(50, 50, 120, 180) 为例。我希望它是动态的,按钮将保持在同一位置。
    猜你喜欢
    • 2013-02-27
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多