Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带动画应用程序的UIPageViewController_Ios_Swift_Uipageviewcontroller - Fatal编程技术网

Ios 带动画应用程序的UIPageViewController

Ios 带动画应用程序的UIPageViewController,ios,swift,uipageviewcontroller,Ios,Swift,Uipageviewcontroller,我通过编程将UIPageViewController写入我的iOS应用程序。但是,当我像这样设置下一个ViewController时: pageContainer.setViewControllers([pages[currentIndex + 1]], direction: UIPageViewControllerNavigationDirection.reverse, animated: true, completion: nil) 我的整个应用程序崩溃了 现在根据我的发现,有两种方法可以

我通过编程将
UIPageViewController
写入我的iOS应用程序。但是,当我像这样设置下一个ViewController时:

pageContainer.setViewControllers([pages[currentIndex + 1]], direction: UIPageViewControllerNavigationDirection.reverse, animated: true, completion: nil)
我的整个应用程序崩溃了

现在根据我的发现,有两种方法可以解决这个问题:

  • UIPageViewController
    transitionStyle
    设置为
    .pageCurl
    (这为我提供了一个非常丑陋和不需要的动画)
  • 或者在设置为新的ViewController时,将
    animated
    属性设置为false(这样就不会产生任何动画,因此也是不需要的)
  • 有人知道怎么解决这个问题吗?因为这两个选项都不可能和我的客户一起飞行

    谢谢

    --编辑

    如问题所述:崩溃消息:

    2018-02-25 13:09:25.728651+0100 WAMP[22669:601029] *** Assertion failure in -[UIPageViewController _flushViewController:animated:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.33.6/UIPageViewController.m:2137
    2018-02-25 13:09:25.855963+0100 WAMP[22669:601029] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Don't know about flushed view <UIView: 0x7fcdc5d167c0; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000644b90>; layer = <CALayer: 0x60000022daa0>>'
    

    我认为在直接设置视图控制器之前,需要先设置UIPageViewController的数据源。转换样式。滚动是页面缓存所需的数据源

    override func viewDidLoad() {
            super.viewDidLoad()
    
            pageContainer = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
            pageContainer.delegate = self
            pageContainer.dataSource = self
            pageContainer.setViewControllers([pages[0]], direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
            view.addSubview(pageContainer.view)
    
        }
    

    你能发布坠机消息吗?@Steve我为你添加了坠机消息。很抱歉我的回复太晚。有趣的是,我看到很多人问类似的问题。您是否可以添加所编写代码的完整示例。我尝试设置一个示例并使用滚动转换,但尚未重新创建此问题。@Steve补充道!:-)令人惊叹的。谢谢我会深入研究这件事,看看能不能弄清楚到底发生了什么。如果/当我解决这个问题时,我会回复。
    override func viewDidLoad() {
            super.viewDidLoad()
    
            pageContainer = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
            pageContainer.delegate = self
            pageContainer.dataSource = self
            pageContainer.setViewControllers([pages[0]], direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
            view.addSubview(pageContainer.view)
    
        }