简体   繁体   English

页面视图控制器未按照其编码的样式转换

[英]page view controller not transitioning in the style it is coded to

Hello new to swift/iphone development, any advice is appreciated! Swift / iphone开发的新手您好,任何建议,不胜感激!

Making a simple page based app consisting of 3 pages, however the view controllers transition using the .pageTurn style when the transition style is set to .scroll in my code 制作一个包含3个页面的基于页面的简单应用程序,但是在我的代码中将过渡样式设置为.scroll时,视图控制器使用.pageTurn样式过渡

let pageController = ViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil) 让pageController = ViewController(transitionStyle:.scroll,navigationOrientation:.horizo​​ntal,选项:nil)

Quite confused why the transition style does not follow what i have coded? 十分困惑,为什么过渡风格不遵循我的编码?

full code: 完整代码:

 let pageController = ViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)

 class ViewController: UIPageViewController {

// page view controllers here
let cardsVC: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "CardsNavController")
let profileVC: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ProfileNavController")
let matchesVC: UIViewController! = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MatchesNavController")

override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = UIColor.white
    dataSource = self
    // loads first view
    setViewControllers([profileVC], direction: .forward, animated: true, completion: nil)
}


// load left view
func goToNextVC() {
    let nextVC = pageViewController(self, viewControllerAfter: viewControllers![0] )!
    setViewControllers([nextVC], direction: .forward, animated: true, completion: nil)
}
// load right view
func goToPreviousVC() {
    let previousVC = pageViewController(self, viewControllerBefore: viewControllers![0] )!
    setViewControllers([previousVC], direction: .reverse, animated: true, completion: nil)
}

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


 }

 // MARK - UIPageViewControllerDataSource
 extension ViewController: UIPageViewControllerDataSource {

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

    // navigate right
    switch viewController {
    case cardsVC:
        return profileVC
    case profileVC:
        return nil
    case matchesVC:
        return cardsVC
    default:
        return nil
    }
}

// navigate left
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

    switch viewController {
    case cardsVC:
        return matchesVC
    case profileVC:
        return cardsVC
    case matchesVC:
        return nil
    default:
        return nil
    }
}

} }

Use like this : 像这样使用:

required init?(coder: NSCoder) {
    super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
}

Have a look at following Project it will Give you expected result I had used here a containerView To present ViewControllers with tableViews using pageViewController 看看下面的项目,它将为您提供预期的结果,我在这里使用了containerView使用pageViewController使用tableViews呈现ViewControllers

Link - https://drive.google.com/open?id=0B2WiGVeE-REPT3loNUFPa0llWGs

ScreenShot of StoryBoard StoryBoard的屏幕截图

在此处输入图片说明

Output - 输出- 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 过渡到新的视图控制器时如何更新状态栏样式? - How to update the status bar style when transitioning to a new view controller? 过渡到新的视图控制器 - Transitioning to a new view controller 问题过渡到根视图控制器 - Problem transitioning to root view controller 查看过渡 - View Transitioning “呈现的视图控制器始终全屏显示”不适用于iOS 7自定义过渡吗? - “presented view controller always full screen” not true for iOS 7 custom transitioning? 使用按钮从一个视图控制器过渡到另一个 - transitioning from one view controller to another using a button Swift:通过TabBar和导航控制器以编程方式从一个视图过渡到另一个视图 - Swift: Programmatically transitioning from 1 view to another via a TabBar and Navigation Controller 将数据从一个视图控制器传递到另一个不转换 - Pass data from one view controller to another without transitioning 如何为Page View Controller提供“垂直覆盖”过渡样式 - how to give Page View Controller a “Cover Vertical” transition style 从一个视图控制器转换到另一个视图控制器时,视图方法的调用顺序是什么? - In what order are view methods called when transitioning from one view controller to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM