那是我的代码:
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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)