你之前在CODE4app发表的那个代码有BUG啊。要怎么解决啊。。 IOS8以上有导航栏就不显示滑动条了。
http://code4app.com/ios/Time-Scroller-With-Slider/4f6af4206803fa2037000000?t=0.09124880214221776#discuss5511278f933bf0f4318b4e75-1
PATH 时间轴的问题求大神指点
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 你知我知皆知 2024-08-03 15:56关注
以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
这个问题是由于IOS 8以上版本的系统不支持滑动条,因此导致了滑动条无法正常显示的问题。解决这个问题的方法如下:
- 在你的代码中添加以下代码:
UIPageControl
。
import UIKit class ViewController: UIViewController, UIPageViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() let pageControl = UIPageControl() view.addSubview(pageControl) // 设置控制器为当前控制器 self.pageViewController = UIPageViewController.currentController as! UIPageViewController self.pageViewController.delegate = self self.view.addSubview(self.pageViewController.view) self.pageViewController!.setViewControllers([self], direction: .forward) // 设置初始页码和方向 } // MARK: - 导航栏相关方法 func pageViewController(_ controller: UIPageViewController, didFinishAnimating finished: Bool, previousViewController: UIViewController?, transitionCompleted transition: UIPageTransition?) { // 如果需要的话,可以在这里做一些额外的操作,比如切换到下一个页面等。 } }
- 添加一个
UIPageViewControllerDelegate
实现类,并重写相应的函数:
class ViewController: UIViewController, UIPageViewControllerDelegate { // ... func pageViewController(_ controller: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { return nil } func pageViewController(_ controller: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { return nil } func pageViewController(_ controller: UIPageViewController, shouldEnableInteractivePopoversFor viewController: UIViewController?) -> Bool { return true } func pageViewController(_ controller: UIPageViewController, shouldStartAnimatingFor viewController: UIViewController?) -> Bool { return true } func pageViewController(_ controller: UIPageViewController, didUpdateTo newPageNumber: Int, from previousPageNumber: Int) {} func pageViewController(_ controller: UIPageViewController, willDisplay viewController: UIViewController, atPageIndex: Int) {} func pageViewControllerDidFinishNavigation(controller: UIPageViewController) {} } extension ViewController: UIPageViewControllerDelegate { func pageViewController(_ controller: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { if viewController == self.self || viewController is TimeScrollerViewController { return viewController } else { return self.pageViewController(viewController.previousViewController!, viewControllerBefore: viewController)! } } func pageViewController(_ controller: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { if viewController == self.self || viewController is TimeScrollerViewController { return viewController } else { return self.pageViewController(viewController.nextViewController!, viewControllerAfter: viewController)! } } func pageViewController(_ controller: UIPageViewController, shouldEnableInteractivePopoversFor viewController: UIViewController?) -> Bool { if viewController is TimeScrollerViewController { return false } else { return true } } func pageViewController(_ controller: UIPageViewController, shouldStartAnimatingFor viewController: UIViewController?) -> Bool { if viewController is TimeScrollerViewController { return false } else { return true } } func pageViewController(_ controller: UIPageViewController, didUpdateTo newPageNumber: Int, from previousPageNumber: Int) {} func pageViewController(_ controller: UIPageViewController, willDisplay viewController: UIViewController, atPageIndex: Int) {} func pageViewControllerDidFinishNavigation(controller: UIPageViewController) {} }
- 创建一个新的
UIViewController
并继承自TimeScrollerViewController
:
class TimeScrollerViewController: UIViewController { var timeSlider: UISlider! override func viewDidLoad() { super.viewDidLoad() setupSlider() } func setupSlider() { timeSlider = UIDatePicker().slider ?? UISlider() timeSlider.minimumValue = 0 timeSlider.maximumValue = 100 timeSlider.value = 50 timeSlider.addTarget(self, action: #selector(timeSliderValueChanged(_:)), for: .valueChanged) view.addSubview(timeSlider) } @objc func timeSliderValueChanged(sender: UISlider!) { print("Time slider value changed to \(sender.value)") } }
现在你应该可以在你的应用中看到滑动条了。
解决 无用评论 打赏 举报 - 在你的代码中添加以下代码:
悬赏问题
- ¥30 STM32 INMP441无法读取数据
- ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
- ¥15 用visualstudio2022创建vue项目后无法启动
- ¥15 x趋于0时tanx-sinx极限可以拆开算吗
- ¥500 把面具戴到人脸上,请大家贡献智慧
- ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
- ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
- ¥30 c#打开word开启修订并实时显示批注
- ¥15 如何解决ldsc的这条报错/index error
- ¥15 VS2022+WDK驱动开发环境