非阻塞UIView动画缩放

时间:2013-05-14 15:17:32

标签: ios objective-c animation block calayer

我想以非阻塞方式动画缩放UIView及其所有内容。目前我这样做......

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.1];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            CGAffineTransform transform = CGAffineTransformMakeScale(1.1,1.1);
            self.view.transform = transform;
    [UIView commitAnimations];

阻止。我宁愿使用像...这样的东西。

[UIView animateWithDuration:0.2
                     animations:^{
                CGAffineTransform transform = CGAffineTransformMakeScale(1.1,1.1);
                self.view.transform = transform;
                     }];

...但animateWithDuration不适用于CALayer / CGAffineTransform转换。如何在不阻挡任何内容的情况下实现相同的动画?

1 个答案:

答案 0 :(得分:5)

尝试使用:

[UIView animateWithDuration:0.2
 animations:^{
   CGAffineTransform transform =
     CGAffineTransformScale(CGAffineTransformIdentity, 2.0, 2.0);
 self.view.transform = transform;
 }];

只需在这个好的答案中添加一个有用的注释,几乎总是你想打开光栅化,所以它看起来很流畅

self.view.layer.shouldRasterize = YES;
[UIView animateWithDuration:0.2
 animations:^{
   CGAffineTransform transform =
     CGAffineTransformScale(CGAffineTransformIdentity, 0.5, 0.5);
 self.view.transform = transform;
 }];