iPhone上的向下滑动视图

时间:2012-02-22 10:11:53

标签: iphone view slidedown

我想创建一个向下滑动的动画,就像链接中的图像一样。当我按下“上一页”时,我希望它向下滑动到屏幕的中心。我真的不确定如何实现它。任何建议都会非常方便。

http://imageshack.us/photo/my-images/718/slideto.png/

2 个答案:

答案 0 :(得分:1)

这看起来像一个UITableView。您可以使用上一个按钮放置一个自定义单元格,这将加载上面的新数据,然后调用scrollToRowAtIndexPath:atScrollPosition:animated:函数来执行动画。

答案 1 :(得分:1)

整个事情很可能是某种UIScrollViewUITableView也是滚动视图)。按下按钮后,使用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];
相关问题