ios - 在 UIPageViewController 中嵌入 UIScrollView 并禁用 pageView 滑动?
问题描述
我有一个UIView
子类(图形)嵌入在 a 的UIScrollview
内部,UIViewController
它是 aUIPageViewController
页面之一...我正在尝试禁用滚动,UIPageViewController
以便用户扫描滚动以查看图形的最左侧而无需分页背部。我怎样才能做到这一点?ScrollView 甚至是这项工作的正确工具吗?
class HistoricalHealthDataViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var graphScrollView: UIScrollView!
@IBOutlet weak var hockeyTrackerGraphView: HockeyTrackerGraphView! {
didSet {
self.hockeyTrackerGraphView.graphableObjects = HFRGraphableObjects
}
}
var HFRGraphableObjects: [HockeyTrackerGraphableObject] = []
override func viewDidLoad() {
super.viewDidLoad()
graphScrollView.delegate = self
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let parentPageViewController = parent as? HistoricalPageViewController {
for gestureRecognizer in parentPageViewController.gestureRecognizers {
print("gestureRecognizer")
gestureRecognizer.isEnabled = false
}
}
}
}
解决方案
你没有显示它的代码,但我假设你实现UIPageViewControllerDataSource
了协议并且在某个地方你有方法:
func pageViewController(UIPageViewController, viewControllerBefore: UIViewController) -> UIViewController? {
}
func pageViewController(UIPageViewController, viewControllerAfter: UIViewController) -> UIViewController? {
}
如果您安排这些方法在禁用分页时返回 nil,则页面视图不会滚动到其他页面。
推荐阅读
- googletest - Linux上的googletest项目结构
- docker - 如何在单独的 Docker 容器中在 Jenkins 中运行单元测试?
- python - Keras - 如何在 CPU 上运行加载的模型
- ansible - 如何在 Ansible(Jinja2 模板)中修复“假”被评估为真
- java - 有人可以给我一个关于如何为一组名称实现图表的例子吗?
- regex - 正则表达式“所有不包含此字符串的内容”
- java - 如何在 Spring Boot 独立应用程序中激活 JMX 监控
- python - 如何整齐地格式化输出?
- java - 每当我添加 OnClickListener 或 Fragment 时,我的应用程序就会崩溃,这是我的 OnClickListener 代码
- javascript - 构建我的应用程序并安装 Google Maps API 后,每当我倾向于搜索位置时,我的应用程序就会崩溃