使2动画中自定义视图 [英] Make 2 animations in Custom View
问题描述
林创建一个自定义视图,它包含例如刷新,*的 LayoutSubviews 的*,按照此<一个方法href=\"http://www.raywenderlich.com/1768/uiview-tutorial-for-ios-how-to-make-a-custom-uiview-in-ios-5-a-5-star-rating-view\"相对=nofollow>教程
Im creating a custom view, it contains methods like Refresh,*LayoutSubviews*, following this tutorial
我要做个动画标签越来越大,它的全宽,然后回到0宽度。使用这种code在刷新法林:
I want a label to be animated growing, to it's full width and then back to 0 width. Im using this code in "refresh" method:
[UIView animateWithDuration:1.3 animations:^{
CGRect frame = CGRectMake(50, 15, 140, 20);
[labelFav setFrame:frame];
} completion:^(BOOL finished) {
//[labelFav setHidden:YES];
[UIView animateWithDuration:1.3 animations:^{
CGRect frame = CGRectMake(50, 15, 0, 20);
[labelFav setFrame:frame];
}];
}];
在code适用于任何其他的看法,但由于这是由于某种原因完工块不执行自定义视图。
什么情况是,它只做第一个块。我在完成块设置一个断点,它停在那里,但动画犯规发生。我试图setHidden标签,仍然它不发生的。
The code works on any other view, but since this is a Custom view by some reason the completion block is not executing. What happens is that it only does the first block. I set a breakpoint in the "completion" block and it stops there but the animation doesnt happen. I tried to setHidden the label and still it doesnt happen.
任何想法?
推荐答案
另一种方式来解决问题。 测试。
Another way to solve problem. Tested.
[UIView animateWithDuration:1.3 animations:^{
CGRect frame = CGRectMake(50, 15, 140, 20);
[labelViewForFav setFrame:frame];
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.3 animations:^{
CGRect frame = CGRectMake(50, 15, 0, 20);
[labelViewForFav setFrame:frame];
} completion:^(BOOL finished) {
}];
}];
问题是,当你做的UILabel宽度小于当前的宽度。动画做得不好。动画不可见的只是跳到最后一帧。
Problem is When you make UIlabel width less than its current width. Animation is not done properly. Animation not visible just jump to final frame.
解决它把你的标签在一个视图改变这个视图的大小,它会正常工作。
to solve it Put your label in a view change the size of this view and it will work properly.
这篇关于使2动画中自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!