【问题标题】:stop animation in the scrollView content offset在 scrollView 内容偏移中停止动画
【发布时间】:2017-02-04 19:07:45
【问题描述】:

我想设置滚动视图的内容偏移量WITHOUT ANIMATION。这是我应用的简单代码,但它不起作用:

[_scrollView setContentOffset:CGPointMake(self.frame.size.width*currentPage, 0) animated:NO];

当我返回滚动视图时执行我的任务后,它的索引重置为 0,然后重置为我当前的索引。没事儿。但是为什么我将动画设置为NO时会出现滚动动画。

请帮忙。

【问题讨论】:

  • 我相信另一个代码正在触发动画。

标签: ios objective-c animation uiscrollview contentoffset


【解决方案1】:

尝试在下面停止动画:

    [CATransaction begin];
    [CATransaction setAnimationDuration:0];
    [CATransaction setDisableActions:YES];
    [_scrollView setContentOffset:CGPointZero animated:NO];
    [CATransaction commit];

【讨论】:

    【解决方案2】:

    这成功了:

    [ UIView performWithoutAnimation:^{ [_scrollView setContentOffset:CGPointMake(self.frame.size.width*currentPage, 0) 动画:NO]; }];

    【讨论】:

      【解决方案3】:

      用途:

      _scrollView.contentOffset = CGPointMake(self.frame.size.width*currentPage, 0);
      

      【讨论】:

      • 在这种情况下,它与您设置内容偏移量的代码行无关。根据您的描述,听起来像是其他东西(例如,您的托管视图控制器的 viewWillAppear 中的一个方法)正在操纵滚动视图。没有看到更多的代码很难说。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      • 2013-06-30
      相关资源
      最近更新 更多