在我目前正在开发的应用程序中,我在两个 UITableViewController 之间切换,UINavigationBar 内有一个 UISegmentedControl。新的 Apple Music 有一个非常简洁的效果,用户可以在 UIPageViewController 内部的 UIViewController 之间切换。关联的 UISegmentedControl 对此进行了平滑调整。基本的 Storyboard设置或代码库应该如何实现这样的目标?
最佳答案
您需要按以下方式使用 uipageviewcontroller 和 uisegmentedcontrol
使用 uipageviewcontroller 并查看本教程以了解其集成 http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
之后,如果您只想在用户单击 uisegment 按钮时执行两个 View 之间的转换,则不要实现此委托(delegate)
(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
设置过渡样式为滚动
现在您需要自定义 uisegmentedcontrol 以提供按下事件动画
在按钮的点击事件上执行设置您需要使用此代码显示的 View Controller
[youPagecontrollerObject setViewControllers:object direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
6 构建并运行
关于ios - 使用 UIPageViewController 和 UISegmentedControl 平滑过渡,就像在 Apple Music App 中一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31492329/