代码之家  ›  专栏  ›  技术社区  ›  samvermette

动画移动和图像缩放uibutton

  •  2
  • samvermette  · 技术社区  · 15 年前

    我希望它是动画的,所以我用 [UIView beginAnimations]

    我试过用 button.imageView.frame (将图像设置为ImageView)但它只对位置设置动画,图像根本不会缩小。

    使用 hateButton.frame (当图像设置为背景图像时),背景图像会缩小,但不会设置动画。

    如何设置缩放uibutton图像的动画?

    2 回复  |  直到 12 年前
        1
  •  5
  •   Mérion    12 年前

    你可以打电话 layoutIfNeeded 之间 [UIView beginAnimations] [UIView commintAnimations] 或与 [UIView animateWithDuration] .

    [UIView animateWithDuration:0.3f animations:^{
        self.myButton.frame = aFrame;    
        [self.myButton layoutIfNeeded];
     }];
    
        2
  •  3
  •   samvermette    15 年前

    我可以使用石英二维:

    // move anchor point without moving frame
    CGRect oldFrame = hateButton.frame;
    hateButton.layer.anchorPoint = CGPointMake(0, 1); // bottom left
    hateButton.frame = oldFrame;
    
    [UIView beginAnimations:nil context:NULL];  
    CGAffineTransform newTransform;
    newTransform = CGAffineTransformMakeScale(0.8, 0.8);
    hateButton.transform = CGAffineTransformTranslate(newTransform, 0, -160);
    [UIView commitAnimations];
    

    确保也导入quartz2d:

    #import <QuartzCore/QuartzCore.h>
    
    推荐文章