动画块复位到原来的位置更新后的文本 [英] Animation Blocks resets to original position after updating text

查看:228
本文介绍了动画块复位到原来的位置更新后的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在测试我的应用程序的IOS 8.释放我发现后,我完成一个动画块,动画重置如果我更新任何标签的文本。我跑用下面所示的一种方法的简单例子。运行这个例子的结果是以下内容:


  • 单击则myButton 第一时间动画运行,但是当复位标签文本被更改。

  • 单击则myButton 第二次 - 动画运行,但不会恢复到原来的位置。

看起来这是因为标签文本不会更改。如果我完全删除该行更新文本,这也从末停止重置动画。

我想解决这个问题,这样的方法运行时,标签文字可以无需重新设置动画更新。

   - (IBAction为)移动:(ID)发送{[UIView的animateWithDuration:0.4延时:0.0
                 选项​​:UIViewAnimationOptionBeginFromCurrentState
                 动画:^ {
                     self.myButton.center = CGPointMake(200,300);
                 }完成:^(BOOL完){                     如果(成品){
                         self.myLabel.text = @感动;
                     }                 }];
}


解决方案

这问题可以通过让自动布局上的UIView设置造成的。严格地说,如果您正在使用自动布局,那么你不应该有生命物体的绝对位置 - 你应该动画它们的约束,而不是

更改标签文本,一旦你的动画正在进行触发布局更新,而iOS洗牌周围的一切都符合原来的视图约束。 (我怀疑这是从iOS7行为上的改变)。

快速修复:取消选中自动布局上来看,这应该按预期工作

I'm currently testing my apps for the release of IOS 8. I noticed that after I performed an animation block, the animation resets if I update the text of any label. I ran a simple example with one method shown below. Running this example results in the following:

  • Clicking myButton the first time- animation runs but resets when the label text is changed.
  • Clicking myButton the second time - animation runs but does not reset to original position.

It seems like this happens because the label text doesn't change. If I completely remove the line updating the text, this also stops the animation from resetting at the end.

I would like to fix this so that when the method runs, the label text can be updated without resetting the animation.

- (IBAction)move:(id)sender {

[UIView animateWithDuration:0.4 delay:0.0
                 options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     self.myButton.center = CGPointMake(200, 300);
                 }completion:^(BOOL finished){

                     if(finished){
                         self.myLabel.text=@"moved";
                     }

                 }];
}

解决方案

This problem can be caused by having Auto Layout set on the UIView. Strictly speaking, if you're using Auto Layout, then you shouldn't animate the absolute position of objects -- you should animate their constraints instead.

Changing the label text once your animation is underway triggers a layout refresh, and iOS shuffles everything around to comply with the original view constraints. (I suspect this is a behavioural change from iOS7).

Quick fix: un-check Auto Layout on the View, and this should work as expected.

这篇关于动画块复位到原来的位置更新后的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆