objective-c - 请教一个 iOS 动画
天蓬老师
天蓬老师 2017-04-18 09:46:05
0
1
522

我想在上面的第一个方块和第二个方块之间插入一个新的方块,我希望的插入动画是新的方块从中心向两边展开(类似ppt中某个动画),同时其他几个方块的宽度能够慢慢变小,最后五个方块能够等宽,就像下面这样

但是我目前的情况是其中的文字会先瞬间移动到最终的位置(也就是说方块变小的过程中文字是不居中的),然后方块的宽度再慢慢变小,不知道为什么,我都是使用autolayout写的动画,我目前的写法是先写上新的方块的top,bottom,leading,trailing约束,然后调用layoutIfNeeded,最后是写上等宽约束,在animate block里面调用layoutIfNeeded。

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
巴扎黑

Your expression is not very clear. The most important thing about autolayout animation is to grasp the state of the view. Simply calling layoutIfNeeded will only render the last effect. The view state must be saved before reaching a state point. To put it simply, after the animation is executed, use layoutIfNeeded to achieve the effect. If there are other animations, you need to use setNeedsLayout. After that, implement the view attributes that need to be changed; finally call layoutIfNeeded again;

// 大概代码就是这样:
// 首先确定 视图的最终位置;也可以是上一次动画结束
[view layoutIfNeeded];
// 然后让视图进入下一次动画准备状态
[view setNeedsLayout];
// *** 这里实现一些变化代码
view.snp.top = ....
// 最后再执行这个。如果是动画,就在 UIView animate 中执行。
[view layoutIfNeeded];
// 这样就 OK 了。
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!