iPhone 上的滑下视图

发布于 2025-01-08 18:41:20 字数 224 浏览 0 评论 0原文

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

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

I want to create a slide-down animation, like in the image in the link. When I press on "Previous", I want it to slide down to the center of the screen. I am not really sure how to implement that. Any suggestion would be really handy.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如若梦似彩虹 2025-01-15 18:41:20

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

This looks like a UITableView. You can place a custom cell with the button Previous, which will load the new data above and then call the scrollToRowAtIndexPath:atScrollPosition:animated: function to perform the animation.

天冷不及心凉 2025-01-15 18:41:20

整个事情很可能是某种 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];

The whole thing is pretty likely a UIScrollView of some sort (UITableViews are scroll views as well). When the buttons is pressed, either use setContentOffset:animated: or scrollRectToVisible:animated: to do the scrolling. The "magic" is just in calculating the correct offset or rect. I'd suggest going with setContentOffset:animated:. It should work roughly like this:

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文