如果视图消失,uiview animate 的完成块永远不会被调用
我注意到一些奇怪的行为。当我启动动画并更改视图(视图不会被关闭!)时,完成处理程序永远不会被调用。
[UIView animateWithDuration:0.1f
delay:0.0f
options:UIViewAnimationCurveEaseOut
animations:^(void){
[myView setHidden:YES];
myLabel.alpha = 0.0f;
someOtherView.frame = CGRectMake(130, bubbleBigRect.origin.y, 61, 65);
[button setHidden:YES];
}
completion:^(BOOL finished){
NSLog(@"Complete %d",finished);
[imageVIew setImage:[UIImage imageNamed:@"myPng.png"]];
}];
}
有什么解决办法吗?
i noticed some strange behavior. When i start a animation and change the View (the view will not dismissed!), the completion handler never get called.
[UIView animateWithDuration:0.1f
delay:0.0f
options:UIViewAnimationCurveEaseOut
animations:^(void){
[myView setHidden:YES];
myLabel.alpha = 0.0f;
someOtherView.frame = CGRectMake(130, bubbleBigRect.origin.y, 61, 65);
[button setHidden:YES];
}
completion:^(BOOL finished){
NSLog(@"Complete %d",finished);
[imageVIew setImage:[UIImage imageNamed:@"myPng.png"]];
}];
}
is there any solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不知道在哪里写它,但我得到了和你一样的东西,但在我的例子中,有时会调用完成块。可能是同一件事。
我发现,如果在动画块中没有任何动画 - 例如,如果您将 alpha=0 设置为 uiview,则 alpha 已经为 0,或者您将 UIScrollView 的内容偏移量设置为相同的内容偏移量(就像我的情况一样) ,未调用完成块。
Don't know where to write it, but I get the same thing that you have, but in my case the completion block was sometimes called. It might be same thing.
I found out that if in the animation block has nothing was animate- for example, if you set alpha=0 to uiview that is alpha is already 0, or you set content offset to UIScrollView to the same content offset (like in my case), the completion block not called.
将其放入动画块中,并将完成后想要执行的所有操作放入 YOUR_SELECTOR 方法中。您现在可以用您的视图做任何您想做的事情,并且仍然有办法在完成后执行某些操作!
Put this in your animation block, and put everything you want to do on completion in YOUR_SELECTOR method. You can now do whatever you want with your view and still have a way of executing something on completion!
在我的例子中,我正在制作动画的视图的帧设置为(0,-568,320,568),并且在动画之后我忘记将帧更改为所需的位置,即(0,0,320,568),因此未调用完成块。更改动画视图的框架对我来说很有效。所以我可以说,例如视图没有什么可显示的(因为框架没有设置在可见区域中)。可能不会调用完成块。
In my case the view which I was animating has its frame set to (0,-568,320,568) and after animation I forget to change the frame to its required position i.e. (0,0,320,568) so the completion block was not being called. Changing the frame of the animated view did the job for me. So I can say if for instance the view has nothing to show(as the frame was not set in visible region). The completion block may not called.
将对
[myView setHidden:YES]
的调用从animations
块移至completion
块。我认为这可能会有所帮助。您仍然可以在animation
块期间(如果您希望它淡出)或在整个调用-[UIView 之前,将
如果你希望它立即消失。myView
的 alpha 设置为 0 animateWithDuration:delay:options:animations:completion:]Move your call to
[myView setHidden:YES]
from theanimations
block to thecompletion
block. I think that will probably help. You can still set the alpha ofmyView
to 0 during theanimation
block (if you want it to fade out), or before the entire call to-[UIView animateWithDuration:delay:options:animations:completion:]
if you want it to disappear right away.