我有一个UIPageVIEwController与WebVIEws作为单元格.
我有另一个简单的UICollectionVIEw用作页面选择器:它的功能是让用户跳转到选中的第X页.
我的代码非常简单:我将触摸的单元格的索引传递给UIPageVIEwController以应用我的“slIDetoPage(index)”函数.
对于iPhone 4S / 5 / 5S,当动画完成后,它会立即返回到旧页面,因此用户无法跳转页面,他只能一次翻页:
这是我的代码:
func slIDetoPage(index: Int,completion: (() -> VoID)?) { let currentVIEwController = pageVIEwController?.vIEwControllers![0] as! WebVIEwVIEwController let count = dataSource.controllers.count let currentPageIndex = dataSource.controllers.indexOf(currentVIEwController)! guard index < count else { return } // Moving forward if index > currentPageIndex { if let vc: WebVIEwVIEwController = dataSource.controllers[index] { self.pageVIEwController!.setVIEwControllers([vc],direction: UIPageVIEwControllerNavigationDirection.Forward,animated: true,completion: { voID in vc.loadContent() }) } } // Moving backward else if index < currentPageIndex { if let vc: WebVIEwVIEwController = dataSource.controllers[index] { self.pageVIEwController!.setVIEwControllers([vc],direction: UIPageVIEwControllerNavigationDirection.Reverse,completion: { voID in vc.loadContent() }) } }}
编辑:
问题出在动画中.如果在setVIEwControllers()函数内设置动画:false,则视图会转到正确的视图.
如果为true,则在动画结束时,网页浏览将转到上一页.
似乎是一个iOS错误.
所以,我添加了一个isAnimated:bool var,仅用于iPad设备的动画;这是我的更新:
func slIDetoPage(index: Int,completion: (() -> VoID)?) { if index >= dataSource.controllers.count || index < 0 { return } let currentVIEwController = pageVIEwController?.vIEwControllers![0] as! WebVIEwVIEwController let currentPageIndex = dataSource.controllers.indexOf(currentVIEwController)! let isAnimated = (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiom.Pad) // Moving forward if index > currentPageIndex { if let vc: WebVIEwVIEwController = dataSource.controllers[index] { self.pageVIEwController!.setVIEwControllers([vc],animated: isAnimated,completion: { complete in vc.loadContent() }) } } // Moving backward else if index < currentPageIndex { if let vc: WebVIEwVIEwController = dataSource.controllers[index] { self.pageVIEwController!.setVIEwControllers([vc],completion: { complete in vc.loadContent() }) } }}总结
以上是内存溢出为你收集整理的ios – UIPageViewController – 以编程方式更改页面在iPhone 4s / 5 / 5s上不起作用全部内容,希望文章能够帮你解决ios – UIPageViewController – 以编程方式更改页面在iPhone 4s / 5 / 5s上不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)