我一直在制作一个在UIVIEwControllers之间滚动的示例应用程序,但重点是我想在滚动结束时和返回第一个UIVIEwController时禁用d跳效果.
这是我的代码:
class PageVIEwController: UIPageVIEwController,UIPageVIEwControllerDataSource,UIPageVIEwControllerDelegate{ var index = 0 var IDentifIErs: NSArray = ["FirstNavigationController","SecondNavigationController"] overrIDe func vIEwDIDLoad() { self.dataSource = self self.delegate = self let startingVIEwController = self.vIEwControllerAtIndex(self.index) let vIEwControllers: NSArray = [startingVIEwController] self.setVIEwControllers(vIEwControllers as [AnyObject],direction: UIPageVIEwControllerNavigationDirection.Forward,animated: false,completion: nil) } func vIEwControllerAtIndex(index: Int) -> UINavigationController! { let storyBoard : UIStoryboard = UIStoryboard(name: "Main",bundle:nil) //first vIEw controller = firstVIEwControllers navigation controller if index == 0 { return storyBoard.instantiateVIEwControllerWithIDentifIEr("FirstNavigationController") as! UINavigationController } //second vIEw controller = secondVIEwController's navigation controller if index == 1 { return storyBoard.instantiateVIEwControllerWithIDentifIEr("SecondNavigationController") as! UINavigationController } return nil } func pageVIEwController(pageVIEwController: UIPageVIEwController,vIEwControllerAfterVIEwController vIEwController: UIVIEwController) -> UIVIEwController? { let IDentifIEr = vIEwController.restorationIDentifIEr let index = self.IDentifIErs.indexOfObject(IDentifIEr!) //if the index is the end of the array,return nil since we dont want a vIEw controller after the last one if index == IDentifIErs.count - 1 { return nil } //increment the index to get the vIEwController after the current index self.index = self.index + 1 return self.vIEwControllerAtIndex(self.index) } func pageVIEwController(pageVIEwController: UIPageVIEwController,vIEwControllerBeforeVIEwController vIEwController: UIVIEwController) -> UIVIEwController? { let IDentifIEr = vIEwController.restorationIDentifIEr let index = self.IDentifIErs.indexOfObject(IDentifIEr!) //if the index is 0,return nil since we dont want a vIEw controller before the first one if index == 0 { return nil } //decrement the index to get the vIEwController before the current one self.index = self.index - 1 return self.vIEwControllerAtIndex(self.index) }}
看看这里:
解决方法 我不知道你能不能. UIPageController不是很容易定制的.就个人而言,当我想在UIVIEwController之间滚动时,我更喜欢使用一个简单的UIVIEwController,它将是一个容器,里面有一个UIScrollVIEw.然后我以编程方式添加UIScrollVIEw的contentSize中的所有控制器.您必须将所有控制器添加为容器的子级.
更新iOS 9
func setupDetailVIEwControllers() { var prevIoUsController: UIVIEwController? for controller in self.controllers { addChildVIEwController(controller) addControllerInContentVIEw(controller,prevIoUsController: prevIoUsController) controller.dIDMovetoParentVIEwController(self) prevIoUsController = controller }}func addControllerInContentVIEw(controller: UIVIEwController,prevIoUsController: UIVIEwController?) { contentVIEw.addSubvIEw(controller.vIEw) controller.vIEw.translatesautoresizingMaskIntoConstraints = false // top controller.vIEw.topAnchor.constraintEqualToAnchor(contentVIEw.topAnchor).active = true // bottom controller.vIEw.bottomAnchor.constraintEqualToAnchor(contentVIEw.bottomAnchor).active = true // trailing trailingContentVIEwConstraint?.active = false trailingContentVIEwConstraint = controller.vIEw.trailingAnchor.constraintEqualToAnchor(contentVIEw.trailingAnchor) trailingContentVIEwConstraint?.active = true // leading let leadingAnchor = prevIoUsController?.vIEw.trailingAnchor ?? contentVIEw.leadingAnchor controller.vIEw.leadingAnchor.constraintEqualToAnchor(leadingAnchor).active = true // wIDth controller.vIEw.wIDthAnchor.constraintEqualToAnchor(scrollVIEw.wIDthAnchor).active = true}
以前的答案
像这样:
scrollVIEw是一个IBOutlet,与ContainerVIEwController的每个边缘都有约束
class ContainerVIEwController: UIVIEwController {@IBOutlet var scrollVIEw: UIScrollVIEw!overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() scrollVIEw.bounces = false scrollVIEw.pagingEnabled = true}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning()}overrIDe func vIEwDIDLayoutSubvIEws() { initScrollVIEw()}func initScrollVIEw(){ let vIEwController1 = storyboard?.instantiateVIEwControllerWithIDentifIEr("VIEwController1") as! VIEwController1 vIEwController1.willMovetoParentVIEwController(self) vIEwController1.vIEw.frame = scrollVIEw.bounds let vIEwController2 = storyboard?.instantiateVIEwControllerWithIDentifIEr("VIEwController2") as! VIEwController2 vIEwController2.willMovetoParentVIEwController(self) vIEwController2.vIEw.frame.size = scrollVIEw.frame.size vIEwController2.vIEw.frame.origin = CGPoint(x: vIEw.frame.wIDth,y: 0) scrollVIEw.contentSize = CGSize(wIDth: 2 * scrollVIEw.frame.wIDth,height: scrollVIEw.frame.height) scrollVIEw.addSubvIEw(vIEwController2.vIEw) self.addChildVIEwController(vIEwController2) vIEwController2.dIDMovetoParentVIEwController(self) scrollVIEw.addSubvIEw(vIEwController1.vIEw) self.addChildVIEwController(vIEwController1) vIEwController1.dIDMovetoParentVIEwController(self)}}总结
以上是内存溢出为你收集整理的ios – 禁用UIPageViewControllerd跳 – Swift [复制]全部内容,希望文章能够帮你解决ios – 禁用UIPageViewControllerd跳 – Swift [复制]所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)