我想创建一个向下滑动的动画,就像链接中的图像一样。当我按下“上一页”时,我希望它向下滑动到屏幕的中心。我真的不确定如何实现它。任何建议都会非常方便。
答案 0 :(得分:1)
这看起来像一个UITableView。您可以使用上一个按钮放置一个自定义单元格,这将加载上面的新数据,然后调用scrollToRowAtIndexPath:atScrollPosition:animated:
函数来执行动画。
答案 1 :(得分:1)
整个事情很可能是某种UIScrollView
(UITableView
也是滚动视图)。按下按钮后,使用setContentOffset:animated:
或scrollRectToVisible:animated:
进行滚动。 “魔术”只是在计算正确的偏移或矩形。我建议去setContentOffset:animated:
。它应该大致如下:
CGPoint p;
p.x = 0;
// Get middle of the view to be centered.
p.y = CGRectGetMidY(myViewThatShouldBeCentered.frame);
// Need to offset it by half the scroll view frame, otherwise
// you'd just see the lower half of the view peeking out at the
// top of the scroll view.
p.y -= CGRectGetHeight(myScrollView.frame) / 2;
[myScrollView setContentOffset:p animated:YES];