【问题标题】:Animating UIView size jumps动画 UIView 大小跳跃
【发布时间】:2013-02-15 22:39:59
【问题描述】:

想要通过改变 UIView 的高度和位置来为它设置动画。第一个动画跳跃?我在 Storyboards 中将 UIView (theView) 的大小设置为 216 的高度。因此应用程序加载并显示 theView。我单击 theView,它的高度迅速跃升至 200+ 像素,然后按应有的动画效果?

- (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");
                                          }];
                     }
                 }];

}

【问题讨论】:

  • 不确定是否理解您的问题。顺便说一句,您在 UIView::animate 中没有“自动反转”选项。
  • @Vinzius 你是对的。

标签: ios objective-c uiview caanimation


【解决方案1】:

尝试移动线条

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

在街区外。放在调用动画方法之前。

【讨论】:

  • Bounds 将使其双向增长,因为它与父级无关。
  • Vinzius 上面的正确答案是 UIViewAnimationCurveLinear。如果您更改为 UIViewAnimationCurveOut 它可以工作,但 UIViewAnimationCurveLinear 或 UIViewAnimationCurveIn 会使其跳转。或者您可以完全删除这些选项并且它可以工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-07
  • 2021-04-27
相关资源
最近更新 更多