gpt4 book ai didi

swift - 如何在禁用 SWIFT 2.0 中突出显示的按钮延迟后在 PageViewController 中启用滚动

转载 作者:行者123 更新时间:2023-11-30 13:37:07 29 4
gpt4 key购买 nike

我只是在 UIPageViewController 中的按钮突出显示延迟方面遇到问题。我现在可以通过将属性“delaysContentTouches”= false 设置为 subview 来解决。但现在我无法再滚动页面了。我搜索论坛并发现“gestureRecognizers”可能会有所帮助。但我不知道如何设置。你能帮我推荐一下吗?

import UIKit

class PageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

var pages = [UIViewController]()

override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
self.dataSource = self

//declare all pages
let page1: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("c01")
let page2: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("c02")
let page3: UIViewController! = storyboard?.instantiateViewControllerWithIdentifier("c03")

pages.append(page1)
pages.append(page2)
pages.append(page3)

setViewControllers([page1], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}


override func viewDidAppear(animated: Bool) {
for view in self.view.subviews {
if view is UIScrollView {
(view as? UIScrollView)!.delaysContentTouches = false
}
}
}



func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = pages.indexOf(viewController) else {
return nil
}
let previousIndex = viewControllerIndex - 1
guard previousIndex >= 0 else {
return pages.last
}
guard pages.count > previousIndex else {
return nil
}
return pages[previousIndex]
}

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = pages.indexOf(viewController) else {
return nil
}
let nextIndex = viewControllerIndex + 1
let orderedViewControllersCount = pages.count
guard orderedViewControllersCount != nextIndex else {
return pages.first
}
guard orderedViewControllersCount > nextIndex else {
return nil
}
return pages[nextIndex]
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

最佳答案

我现在就可以做到。

uipageviewcontroller 是不可能的。我必须转移到 uiscrollviewcontroller然后将其子类化并重写函数 TouchesShouldCancelInContentView 以使我的所有 UIButton 为 true。

现在我可以立即点击按钮,并且仍然可以按住手指滚动。

关于swift - 如何在禁用 SWIFT 2.0 中突出显示的按钮延迟后在 PageViewController 中启用滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35955498/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com