码迷,mamicode.com
首页 > 其他好文 > 详细

可以做动画的属性

时间:2017-01-14 11:24:25      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:nim   period   更新   ret   shu   orm   uri   upd   技术分享   

Changes to several view properties can be animated—that is, changing the property creates an animation that conveys the change to the user over a short period of time. The UIView class does most of the work of performing the actual animations but you must still indicate which property changes you want to be animated.

也就是说这些动属性的变化在动画的线程中时,就会有动画的效果。

技术分享

        UIView.animateWithDuration(0.5) {
            if Holder.animated
            {
                self.myButton?.bounds = CGRectMake(0, 0, s_ScreenWidth, 30);
                Holder.animated = false
            }
            else
            {
                self.myButton?.bounds = CGRectMake(0, 0, s_ScreenWidth/2, 60);
                Holder.animated = true
            }
        }

对于另一些属性,即使在动画的block中设置,也不会有动画效果。

技术分享

        UIView.animateWithDuration(0.5) {
            if Holder.animated
            {
                self.myButton?.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10)
                Holder.animated = false
            }
            else
            {
                self.myButton?.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, -10)
                Holder.animated = true
            }
        }

setNeedsLayout与layoutIfNeeded

  • setNeedsLayout

    Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.

    this method makes a note of the request and returns immediately. Because this method does not force an immediate update,

也就是说这个函数并不会是使界面马上更新,要等到下一次更新(页面刷新?)时。在动画的block中设置这个属性也不会有动画。
- layoutIfNeeded

Lays out the subviews immediately

因此调用这个函数会马上是界面更新。如果在block中调用这个函数,会有动画的效果。

技术分享

    UIView.animateWithDuration(0.5) {
        if Holder.animated
        {
            self.myButton?.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10)
            self.myButton?.setNeedsLayout()
        }
        else
        {
            self.myButton?.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, -10)
            self.myButton?.layoutIfNeeded()
            Holder.animated = true
        }

可以做动画的属性

标签:nim   period   更新   ret   shu   orm   uri   upd   技术分享   

原文地址:http://www.cnblogs.com/huahuahu/p/ke-yi-zuo-dong-hua-de-shu-xing.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!