最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

iOS

旗下网站admin39浏览0评论

iOS

iOS

iOS - 在动画过渡期间更新标签?(iOS - Updating label during animation transition?)

我在屏幕上有一个包含几个标签的UIView。 我试图进行翻转视图的过渡,一旦我在动画的一半,我希望能够更新标签。 我怎样才能做到这一点?

[UIView transitionWithView:self.myView duration:.7 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{ // It doesn't update the labels here, until I scoll the tableview (containing the view) //[self.myView update]; } completion:^(BOOL finished){ // It doesn't look nice here because it doesn't look smooth, the label flashes and changes after the animation is complete //[self.myView update]; }];

I have a UIView on the screen that contains a few labels. I am trying to have a transition where flips the view, and as soon as I am half way through the nimation I want to be able to update the labels. How Can I achieve this?

[UIView transitionWithView:self.myView duration:.7 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{ // It doesn't update the labels here, until I scoll the tableview (containing the view) //[self.myView update]; } completion:^(BOOL finished){ // It doesn't look nice here because it doesn't look smooth, the label flashes and changes after the animation is complete //[self.myView update]; }]; 最满意答案

问题是我启用了shouldRasterize,这不允许在动画期间更新内容。 解决方案是在动画之前关闭光栅化并在动画完成后将其重新打开。

我没有摆脱光栅化的原因是视图在tableView中,并且在滚动tableView时光栅化仍然有帮助。

self.layer.shouldRasterize = NO;[UIView transitionWithView:self duration:animationDuration options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{/*update the content here, I did it outside of the transition method though*/} completion:^(BOOL finished){ if (finished) { self.layer.shouldRasterize = YES; } }];

The problem was that I had shouldRasterize enabled which was not allowing the content to be updated during an animaton. Solution was to turn off rasterization before the animation and turn it back on after animation completion.

The reason why I didn't get rid of rasterization is that the view is inside a tableView, and rasterization still helps while scrolling through the tableView.

self.layer.shouldRasterize = NO;[UIView transitionWithView:self duration:animationDuration options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{/*update the content here, I did it outside of the transition method though*/} completion:^(BOOL finished){ if (finished) { self.layer.shouldRasterize = YES; } }];

发布评论

评论列表(0)

  1. 暂无评论