【问题标题】:Non-blocking UIView animated scaling非阻塞 UIView 动画缩放
【发布时间】:2013-05-14 15:17:31
【问题描述】:

我想以非阻塞方式对 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 转换。如何在不阻塞任何东西的情况下实现相同的动画?

【问题讨论】:

  • 也许只是手动更改视图框架的大小和原点,而不是使用转换,更方便的工作,但它应该工作

标签: ios objective-c animation block calayer


【解决方案1】:

尝试使用:

[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;
 }];

【讨论】:

    猜你喜欢
    • 2012-10-08
    • 2019-01-27
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 1970-01-01
    相关资源
    最近更新 更多