在自定义视图中制作2个animation

我创build一个自定义的视图,它包含像本教程之后的 刷新 ,* LayoutSubviews *的方法

我想要一个标签animation越来越大,它的全宽,然后回到0宽度。 我在“刷新”方法使用此代码:

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

该代码可以在任何其他视图上工作,但是由于某种原因,这是一个自定义视图,所以完成块没有执行。 发生什么事是它只做第一块。 我在“完成”块中设置了一个断点,它停在那里,但animation不会发生。 我试图设置隐藏的标签,但仍然没有发生。

有任何想法吗?

从您的界面生成器主屏幕删除自动布局。 你的观点可能会改变它的框架,但自动布局(可能)迫使它在别处…

解决问题的另一种方法。 testing。

 [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宽度小于其当前宽度。 animation不正确。 animation不可见只是跳转到最后一帧。

解决它把你的标签在视图中改变这个视图的大小,它会正常工作。