动画UIView的增长/收缩 [英] Animate UIView grow/shrink

查看:302
本文介绍了动画UIView的增长/收缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UILabel我想动画增长和收缩。虽然大小的变化,我需要左下角保持静态,这样它总是直接出现底部工具栏上方。我使用下面的code键使标签成长:

I have a UILabel I want to animate growing and shrinking. While the size changes I need the bottom left corner to remain static so that it always appears directly above a bottom toolbar. I am using the following code to make the label grow:

[UIView animateWithDuration:kAnimationDuration delay:0.0 options:UIViewAnimationCurveEaseInOut 
                 animations:^{  
    CGFloat lblHeight = 42.0f;
    [label setFrame:CGRectMake(0.0, 
                CGRectGetMaxY(self.view.bounds) - kBottomBarHeight - lblHeight, 
                CGRectGetMaxX(self.view.bounds), 
                lblHeight)];                
} completion:^(BOOL finished) { }];

和使其收缩我使用相同的逻辑除了lblHeight设为17.0f

and to make it shrink I use the same logic except that lblHeight is set to 17.0f

该视图正常生长,但是当我试图缩小它的框架变化​​的动画没有动画。它的光点到新的大小,然后进入动画新原点/位置。我需要的帧变化进行动画处理。任何人都可以看到我在做什么错?

The view correctly grows but when I try to shrink it the frame change animation is not animated. It blips into the new size and then animates into the new origin/location. I need the frame change to be animated. Can anyone see what I'm doing wrong?

推荐答案

一些修修补补之后,我已经成功通过执行以下操作来获得所需的行为。

After some tinkering I've managed to get the desired behavior by doing the following.

在展开方法,我使用的UIView动画改变帧。
在收缩的方法,我使用的UIView动画改变边界和中心。

In the expand method, I use the UIView animation to alter the frame. In the shrink method, I use the UIView animation to alter the bounds and center.

我有点困惑,为什么这工作,但试图缩小与帧没有。如果任何人都可以分享一些洞察到这一点,将是巨大的。

I'm a little baffled as to why this works but trying to shrink with the frame does not. If anyone can share some insight into this that would be great.

这篇关于动画UIView的增长/收缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆