2014-03-04 51 views
0

我有一个简单的覆盖层,包含一个白色的UI视图 - 其中包含一个活动指标,在等待服务器响应时显示。IOS 7 - UiView的动画高度

当服务器的答复是完成我想动画的UIView的高度,一旦高度动画完成显示隐藏返回按钮 -

我已经走到这一步,(这伊夫改编自以下另一篇文章) - 但我不确定我是否在正确的轨道上!?

- (void) showAnimation 
{ 
    [_overlayInner animateWithDuration:60 
       animations:^{ 
        CGRect frame = left.frame; 
        // adjust size of frame to desired value 
        frame.size.height = 120; 
        left.frame = frame; // set frame on your view to the adjusted size 
       } 
       completion:^(BOOL finished){ 
        [_rtnBtn setHidden:NO]; 
       }]; 
} 

上面显示的第一行注明“的UIView的没有可见的接口声明的选择具有持续时间的动画”的错误。 (_overlayInner是我想要动画的视图)

我吠叫了错误的树吗?还是有更简单的方法来制作uiview高度的动画?

+0

我知道这很愚蠢(Xcode有时候会这样),但是确保'}'和'c'之间有一个空格。 –

回答

8

该方法是UIView上的类方法。

你应该调用它像这样...

[UIView animateWithDuration:60 
      animations:^{ 
       CGRect frame = left.frame; 
       // adjust size of frame to desired value 
       frame.size.height = 120; 
       left.frame = frame; // set frame on your view to the adjusted size 
      } 
      completion:^(BOOL finished){ 
       [_rtnBtn setHidden:NO]; 
      }]; 

documentation这种方法。

你可以看到声明...

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion 

的+意味着它是一个类的方法不是一个实例方法。

编辑

只是为了解释这是如何工作的?

[UIView animateWithDuration:60 //this is the length of time the animation will take 
      animations:^{ 
       //this is where you change the stuff to its "final" state 
      } 
      completion:^(BOOL finished){ 
       //this gets run after the animation is complete 
      }]; 

所以...如果你有一个观点叫myButton其当前帧等于CGRectMake(10, 10, 100, 44)和你想要在5秒内向右移动20点,然后登录到动画已停止的控制台,然后您可以做...

[UIView animateWithDuration:5 
      animations:^{ 
       myButton.frame = CGRectMake(30, 10, 100, 44); 
      } 
      completion:^(BOOL finished){ 
       NSLog(@"The animation has now stopped!"); 
      }]; 

如果你想在15秒内的按钮的高度的两倍,那么你会怎么做?

[UIView animateWithDuration:15 
      animations:^{ 
       myButton.frame = CGRectMake(10, 10, 100, 88); 
      } 
      completion:^(BOOL finished){ 
       NSLog(@"The animation has now stopped!"); 
      }]; 

只是一个快速注

要小心,如果你正在使用自动版式,并试图动画通过改变框架的东西。他们在一起打球不好。如果你只是学习iOS并习惯于动画,然后玩,而不使用AutoLayout。然后,您可以尝试使用AutoLayout进行动画制作。

+0

欢呼@Fogmeister - 我可能会在这里背后 - 但我在哪里定义或通过了我想要动画的视图? – Dancer

+0

让我编辑我的答案来解释。 – Fogmeister

+0

酷确定这将是王牌欢呼 – Dancer