I have a vertical paged scrollview inside a horizontal scrollview. The horizontal scrollview works but the vertical one does not.
I used scrollView.contentSize=CGSize(500,2000)
on vertical scrollview but it is still not working.
Now what is the problem?
I should say, the vertical one added to view, programmatically using xib.
this is my Main.swift (i have no storyboard):
class test: UIViewController {
@IBOutlet weak var scroll: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidLayoutSubviews() {
let myView3:TourDetailsDescription = TourDetailsDescription(frame: CGRect(x: 0, y: 0, width: scroll.frame.width, height: scroll.frame.height))
myView3.getView().frame.origin.x = CGFloat(2*scroll.frame.width)
scroll.addSubview(myView3)
let img1:UIImageView = UIImageView(image: UIImage(named: "kavir"))
img1.frame = CGRect(x: 0, y: 0, width: 300, height: 600)
myView3.mainScroll.addSubview(img1)
myView3.mainScroll.contentSize = CGSize(width: 300, height: 600)
self.scroll.contentSize = CGSize(width:UIScreen.main.bounds.width * CGFloat(2), height:self.scroll.frame.height)
}
}
and my TourDetailsDescription.swift :
class TourDetailsDescription: UIView {
@IBOutlet weak var mainScroll: UIScrollView!
var parent:UIView!
@IBOutlet var contentView: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
commitInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commitInit()
}
private func commitInit(){
Bundle.main.loadNibNamed("TourDetailsDescription", owner: self, options: nil)
addSubview(contentView)
contentView.frame = self.bounds
contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
func getView()->UIView{
return contentView
}
}
May be this help you :), this is working on playground
class ScrollingViewController : UIViewController {
override func loadView() {
let contentView = UIView(frame: CGRect(x: 0, y: 20, width: 2000, height: 200))
contentView.backgroundColor = .green
let scrollView = UIScrollView()
scrollView.contentSize = contentView.frame.size
scrollView.addSubview(contentView)
scrollView.flashScrollIndicators()
scrollView.backgroundColor = .white
let verticalContainerView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
verticalContainerView.backgroundColor = .blue
let verticalContentView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 2000))
verticalContentView.backgroundColor = .red
let verticalScrollView = UIScrollView(frame: verticalContainerView.frame)
verticalScrollView.contentSize = verticalContentView.frame.size
verticalScrollView.addSubview(verticalContentView)
scrollView.flashScrollIndicators()
verticalScrollView.backgroundColor = .white
verticalContainerView.addSubview(verticalScrollView)
contentView.addSubview(verticalContainerView)
self.view = scrollView
}
}
PlaygroundPage.current.liveView = ScrollingViewController()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.