【问题标题】:Animation Grow/Decrease Size imageView iOS动画增大/减小尺寸 imageView iOS
【发布时间】:2013-10-08 12:10:23
【问题描述】:

我正在尝试使用 CGAffineTransformMakeScale 为自定义按钮设置动画,如下所示:

if (stateButton == 0) { //The button is gonna appear

    self.selected = YES;

    self.imageView.transform = CGAffineTransformMakeScale(0.01, 0.01);

    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        // animate it to the identity transform (100% scale)
        self.imageView.transform = CGAffineTransformIdentity;
    } completion:nil];

}
else if (stateButton ==1) { //The button is gonna disappear


    self.imageView.transform = CGAffineTransformMakeScale(1, 1);

    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        // decrease button
        self.imageView.transform = CGAffineTransformMakeScale(.01, .01);
    } completion:^(BOOL finished){

        self.selected = NO;
    }];
}   

按钮完美地增长到原始大小,但是,我不知道原因,但是当我单击按钮减小它时,它会从比原始大小大 100% 的大小减小到原始大小,而不是像我在代码中指出的那样开始减小原始大小并达到 0.01 的比例。

请帮忙!!

【问题讨论】:

    标签: ios uiimageview cgaffinetransform cgaffinetransformscale


    【解决方案1】:

    您可以使用以下代码为图像视图的大小设置动画

    [UIView animateWithDuration:2.0 animations:^{
        self.imageView.transform = CGAffineTransformMakeScale(0.5, 0.5);
    } 
    completion:^(BOOL finished){
        [UIView animateWithDuration:2.0 animations:^{
            self.imageView.transform = CGAffineTransformMakeScale(1, 1);    
        }];
    }];
    

    这将使 imageview 最初的大小减小,当动画结束时,它会通过动画恢复到原来的大小。

    【讨论】:

      【解决方案2】:

      SWIFT 3 版本

      UIView.animate(withDuration: 2.0, animations: {() -> Void in
          self.imageView?.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
      }, completion: {(_ finished: Bool) -> Void in
          UIView.animate(withDuration: 2.0, animations: {() -> Void in
              self.imageView?.transform = CGAffineTransform(scaleX: 1, y: 1)
          })
      })
      

      【讨论】:

        猜你喜欢
        • 2020-01-24
        • 1970-01-01
        • 2015-01-27
        • 2017-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多