ios – 防止刷UIPageViewController时出现的白色间隙

ios – 防止刷UIPageViewController时出现的白色间隙,第1张

概述我已经以这种方式实现了UIPageViewController: GalleryViewController:是PageViewController的容器 PageViewController:是pageViewController,我将它作为子视图添加到GalleryViewController. PageContentViewController:我把它放在UIImageView中作为页面视图 我已经以这种方式实现了UIPageVIEwController:

galleryVIEwController:是PageVIEwController的容器

PageVIEwController:是pageVIEwController,我将它作为子视图添加到galleryVIEwController.

PageContentVIEwController:我把它放在UIImageVIEw中作为页面视图控制器的内容.

一切进展顺利,但是当我在图像之间滑动时,会发生奇怪的事情.白色缺口出现上行空间.

奇怪的是,当我完成滚动时,它会自动伸展.

这是galleryVIEwController的代码,它是PageVIEwController的容器:

import UIKitclass PageVIEwController: UIVIEwController,UIPageVIEwControllerDataSource,UIPageVIEwControllerDelegate {var startIndex:Int = 0var pageVIEwController : UIPageVIEwController!overrIDe func vIEwDIDLoad() {    self.navigationController?.hIDesbarsOnTap = true;    reset()}func reset() {    /* Getting the page VIEw controller */    pageVIEwController = self.storyboard?.instantiateVIEwControllerWithIDentifIEr("PageVIEwController") as UIPageVIEwController    self.pageVIEwController.dataSource = self    let pageContentVIEwController = self.vIEwControllerAtIndex(0)    self.pageVIEwController.setVIEwControllers([pageContentVIEwController!],direction: UIPageVIEwControllerNavigationDirection.Forward,animated: true,completion: nil)    self.pageVIEwController.vIEw.frame = CGRectMake(0,self.vIEw.frame.wIDth,self.vIEw.frame.height)    self.addChildVIEwController(pageVIEwController)    self.vIEw.addSubvIEw(pageVIEwController.vIEw)    self.pageVIEwController.dIDMovetoParentVIEwController(self)    println("\(startIndex) start index")}overrIDe func dIDReceiveMemoryWarning() {    super.dIDReceiveMemoryWarning()    // dispose of any resources that can be recreated.}func pageVIEwController(pageVIEwController: UIPageVIEwController,vIEwControllerAfterVIEwController vIEwController: UIVIEwController) -> UIVIEwController? {    var index = (vIEwController as PageContentVIEwController).pageIndex!    index++    if(index >= Constants.Statics.images.count){        return nil    }    return self.vIEwControllerAtIndex(index)}func pageVIEwController(pageVIEwController: UIPageVIEwController,vIEwControllerBeforeVIEwController vIEwController: UIVIEwController) -> UIVIEwController? {    var index = (vIEwController as PageContentVIEwController).pageIndex!    if(index <= 0){        return nil    }    index--    return self.vIEwControllerAtIndex(index)}func vIEwControllerAtIndex(index : Int) -> UIVIEwController? {    if((Constants.Statics.images.count == 0) || (index >= Constants.Statics.images.count)) {        return nil    }    let pageContentVIEwController = self.storyboard?.instantiateVIEwControllerWithIDentifIEr("PageContentVIEwController") as PageContentVIEwController    pageContentVIEwController.pageIndex = index    return pageContentVIEwController}}

我该怎么做才能防止拉伸和滑动时的白色间隙

更新:

发生了一件奇怪的事情,我将pageVIEwController Transition Style更改为Page Curl,问题没有出现.听起来像滚动!

解决方法 错误的起源是UIImageVIEw的约束.

当您开始滚动时,仅调用vIEwWillAppear,并且尚未计算autolayout,滚动完成后显示视图,视图开始计算autolayout,并且在autolayout完成后发生vIEwDIDAppear.

您可以通过在PageContentVIEwController中添加以下代码来检查

overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    imageVIEw.image = UIImage(named: "UpcomingGamesBg")    println("vIEwDIDLoad imageVIEw Frame : \(imageVIEw.frame) pageIndex : \(pageIndex)")  }  overrIDe func vIEwWillAppear(animated: Bool) {    super.vIEwWillAppear(animated)    println("vIEwWillAppear imageVIEw Frame : \(imageVIEw.frame) pageIndex : \(pageIndex)")  }  overrIDe func vIEwDIDAppear(animated: Bool) {    super.vIEwDIDAppear(animated)    println("vIEwDIDAppear imageVIEw Frame : \(imageVIEw.frame) pageIndex : \(pageIndex)")  }

因为,imageVIEw的布局参考顶部布局指南,并且顶部布局指南在计算自动布局之前和之后可以有不同的值,你有这个BUG.

因此,要解决这个问题,您可以更改图像视图的约束并使它们成为父视图的亲戚(因为pageContentVIEwController就像一个子视图,而pagerVIEwController将管理顶部和底部边距),如下所示:

有了这个你可以修复这个BUG,但要小心你应该为pageVIEwController.vIEw添加一些约束

更新

例如,要支持navigationbar / Tabbar,您应该在vIEwDIDLoad中添加一些约束(在vIEw.addSubvIEw(pageVIEwController.vIEw)之后):

pageVIEwController.vIEw.setTranslatesautoresizingMaskIntoConstraints(false)    let topConstraint = NSLayoutConstraint(item: pageVIEwController.vIEw,attribute: NSLayoutAttribute.top,relatedBy: NSLayoutRelation.Equal,toItem: topLayoutGuIDe,attribute: NSLayoutAttribute.Bottom,multiplIEr: 1.0,constant: 0)    let bottomConstaint = NSLayoutConstraint(item: pageVIEwController.vIEw,toItem: bottomLayoutGuIDe,constant: 0)    let leadingConstraint = NSLayoutConstraint(item: pageVIEwController.vIEw,attribute: NSLayoutAttribute.Leading,toItem: vIEw,constant: 0)    let trailingConstraint = NSLayoutConstraint(item: pageVIEwController.vIEw,attribute: NSLayoutAttribute.Trailing,constant: 0)    vIEw.addConstraints([topConstraint,bottomConstaint,leadingConstraint,trailingConstraint])

最好的祝福,

总结

以上是内存溢出为你收集整理的ios – 防止刷UIPageViewController时出现的白色间隙全部内容,希望文章能够帮你解决ios – 防止刷UIPageViewController时出现的白色间隙所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1008048.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存