gpt4 book ai didi

ios - 页面 View Controller 隐藏指示点并停在最后一页(无法返回)

转载 作者:行者123 更新时间:2023-11-30 12:40:47 26 4
gpt4 key购买 nike

我的项目中有一个页面控件,我想做两件事:1.我想隐藏最后一页的指示点2.我想锁定(页面VC(我的类(class)))中的最后一页,使我无法返回第一页这是我的代码

class pageVC : UIPageViewController , UIPageViewControllerDataSource , UIPageViewControllerDelegate {

lazy var VCArr : [UIViewController] = {
return [self.VCInstance(name : "FirtsVC"),
self.VCInstance(name : "SecondVC"),
self.VCInstance(name :"ThirdVC"),
self.VCInstance(name :"FourthVC"),
self.VCInstance(name :"FivethVC")]
}()

private func VCInstance(name : String) -> UIViewController {
return UIStoryboard(name : "Main" , bundle : nil).instantiateViewController(withIdentifier: name)
}

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

if VCArr.last != nil {
print("first Page Reached!")
}

if let firstVC = VCArr.first {
setViewControllers([firstVC] , direction: .forward , animated: true, completion: nil)
}
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let pageVC = UIPageControl()

for view in self.view.subviews {
if view is UIScrollView {
view.frame = UIScreen.main.bounds
}else if view is UIPageControl{
view.backgroundColor = UIColor.clear
pageVC.numberOfPages = 5
pageVC.center = self.view.center
pageVC.layer.position.y = self.view.frame.height - 180 ;
}
}
}

public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?{
guard let viewControllerIndex = VCArr.index(of: viewController) else {
return nil
}

let previousIndex = viewControllerIndex-1
guard previousIndex >= 0 else {
return VCArr.last
}

guard VCArr.count > previousIndex else {
return nil
}

return VCArr[previousIndex]
}


public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?{
guard let viewControllerIndex = VCArr.index(of: viewController) else {
return nil
}

let nextIndex = viewControllerIndex+1
guard nextIndex < VCArr.count
else {
return VCArr.first
}

guard VCArr.count > nextIndex else {
return nil
}
return VCArr[nextIndex]
}


public func presentationCount(for pageViewController: UIPageViewController) -> Int{
return VCArr.count
}

public func presentationIndex(for pageViewController: UIPageViewController) -> Int{
guard let firstViewController = viewControllers?.first , let firstViewControllerIndex = VCArr.index(of: firstViewController) else {
return 0
}

return firstViewControllerIndex
}
public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if (VCArr.last!.isViewLoaded)
{
print("It is Done!!!")
}
}

最佳答案

更改此设置,使页面 View 在最后一个页面时返回到第一个页面:

let nextIndex = viewControllerIndex+1
guard nextIndex < VCArr.count
else {
return nil //was VCArr.first
}

要使其隐藏,首先将 let pageVC = UIPageControl() 移至 class pageVC : UIPageViewController , UIPageViewControllerDataSource , UIPageViewControllerDelegate { 下方,使其在类中公开。然后添加:

if nextIndex == VCArr.count{
pageVC.isHidden = true
}

关于ios - 页面 View Controller 隐藏指示点并停在最后一页(无法返回),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42246909/

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