2013-02-15 169 views
0

Tyring通过改变其高度和位置来动画UIView动画。第一个动画跳转?我有在故事板中设置的UIView(theView)的大小为216的高度。因此,应用程序加载并显示该视图。我点击该视图,它会立即跳到200+像素的高度,然后按照它应该的动画效果?动画UIView大小跳跃

- (void)singleTapAction:(UIGestureRecognizer *)singleTap { 
UIView *view = singleTap.view; 
[UIView animateWithDuration:1.2 delay:0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^{ 
    CGRect theFrame = self.theView.frame; 
    theFrame.size.height += 100.f; <!-- when it hits here the view jumps then animates 
    self.theView.frame = theFrame; 
} 
       completion:^(BOOL finished) { 
        if(finished){ 
         [UIView animateWithDuration:1.2 delay:0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^{ 
          CGRect theFrame = self.theView.frame; 
          theFrame.origin.y -= 100.f; 
          self.theView.frame = theFrame; 
         } 
              completion:^(BOOL finished) { 
               NSLog(@"animations complete"); 
              }]; 
        } 
       }]; 

}

+0

不确定要理解你的问题。只是不,顺便说一句,你有UIView :: animate中的“自动反向”选项。 – Vinzius 2013-02-15 22:56:19

+0

@Vinzius你是对的。 – jdog 2013-02-16 04:38:35

回答

0

尝试移动线

CGRect theFrame = self.theView.frame; 
theFrame.size.height += 100.f; <!-- when it hits here the view jumps then animates 

外块。在动画方法被调用之前放置它。

+0

界限将使其双向增长,因为它不相对于其父项。 – jdog 2013-02-16 04:38:12

+0

我之前错了,试着编辑答案。 – Shashank 2013-02-16 04:58:10

+0

上面的Vinzius有正确答案,问题是UIViewAnimationCurveLinear。如果更改为UIViewAnimationCurveOut,它将起作用,但UIViewAnimationCurveLinear或UIViewAnimationCurveIn会使其跳跃。或者你可以完全删除选项,它的工作原理。 – jdog 2013-02-16 05:03:12