ios – 将UIViewController添加到UIScrollView swift 3

ios – 将UIViewController添加到UIScrollView swift 3,第1张

概述我正在研究ScrollView.目前我在ScrollView中有两个图像,我想在ScrollView中添加至少一个新的UIViewController. 那是我的代码: self.scrollView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.scrollView.frame.height) 我正在研究ScrollVIEw.目前我在ScrollVIEw中有两个图像,我想在ScrollVIEw中添加至少一个新的UIVIEwController.

那是我的代码:

self.scrollVIEw.frame = CGRect(x: 0,y: 0,wIDth: self.vIEw.frame.wIDth,height: self.scrollVIEw.frame.height)    let scrollvIEwHeight = self.scrollVIEw.frame.height    let scrollvIEwWIDth = self.scrollVIEw.frame.wIDth    var imgOne = UIImageVIEw(frame: CGRect(x: 0,wIDth: scrollvIEwWIDth,height: scrollvIEwHeight))    var imgTwo = UIImageVIEw(frame: CGRect(x: scrollvIEwWIDth,height: scrollvIEwHeight))    imgOne.image = UIImage(named: "prevIEw1")    imgTwo.image = UIImage(named: "prevIEw2")    self.scrollVIEw.addSubvIEw(imgOne)    self.scrollVIEw.addSubvIEw(imgTwo)    self.scrollVIEw.contentSize = CGSize(wIDth: self.scrollVIEw.frame.wIDth * 2,height: self.scrollVIEw.frame.height)    self.scrollVIEw.isPagingEnabled = true

设计:

The first one is the root ViewController,where the ScrollView is and the second one I want to add in the ScrollView

解决方法 试试看,看看:

self.scrollVIEw.frame = CGRect( <set frame> )var imgOne = UIImageVIEw(frame: CGRect( <set frame> ))var imgTwo = UIImageVIEw(frame: CGRect( <set frame> ))var vcVIEw = UIVIEw(frame: CGRect( <set frame> ))addChildVC(vcVIEw: vcVIEw)imgOne.image = UIImage(named: "prevIEw1")imgTwo.image = UIImage(named: "prevIEw2")self.scrollVIEw.addSubvIEw(imgOne)self.scrollVIEw.addSubvIEw(imgTwo)self.scrollVIEw.addSubvIEw(vcVIEw)self.scrollVIEw.contentSize = CGSize( <set content size> )self.scrollVIEw.isPagingEnabled = true

添加子视图控制器

func addChildVC(vcVIEw: UIVIEw){let testVC = self.storyboard?.instantiateVIEwControllerWithIDentifIEr("testIDentifIEr") as! TestVIEwController    testVC.vIEw.frame = vcVIEw.bounds    vcVIEw.addSubvIEw(testVC.vIEw)    self.addChildVIEwController(testVC)    testVC.dIDMovetoParentVIEwController(self)}
总结

以上是内存溢出为你收集整理的ios – 将UIViewController添加到UIScrollView swift 3全部内容,希望文章能够帮你解决ios – 将UIViewController添加到UIScrollView swift 3所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存