2017-05-23 1 views
0

Ich erstelle eine UIScrollView von code.The einzige Problem ist das Scrollen funktioniert nicht durch Los des Beitrags gehen, aber nichts gefunden. Hier ist mein Code Jede Hilfe sehr geschätzt.UIScrollView scrollte nicht?

class ShopDetailviewController : UIViewController { 


var MainScrollView : UIScrollView? 

let viewForScrollview : UIView = { 

    let view = UIView() 
    view.backgroundColor = UIColor.darkGray 
    return view 
}() 

let shopNameandAddresView : UIView = { 

    let view = UIView() 
    view.backgroundColor = UIColor.black 
    return view 
}() 

let timePaymentDetail : UIView = { 

    let view = UIView() 
    view.backgroundColor = UIColor.blue 
    return view 
}() 


let shopImage : UIImageView = { 

    let shopeImage = UIImageView() 
    shopeImage.backgroundColor = UIColor.green 
    return shopeImage 

}() 

let ratingStarLable : UILabel = { 

    let ratingStratLable = UILabel() 
    ratingStratLable.backgroundColor = UIColor.red 
    ratingStratLable.text = "3.5" 
    return ratingStratLable 

}() 

let shopName : UILabel = { 

    let shopName = UILabel() 
    shopName.backgroundColor = UIColor.gray 
    shopName.text = "Kimling" 
    return shopName 

}() 

let shopLocation : UILabel = { 

    let shopLocation = UILabel() 
    shopLocation.backgroundColor = UIColor.white 
    shopLocation.text = "Kondhwa" 
    return shopLocation 

}() 

let seprater : UIView = { 

    let seprater = UIView() 
    seprater.backgroundColor = UIColor.white 
    return seprater 
}() 



override func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(true) 

    navigationController?.navigationBar.tintColor = .white 
    view.backgroundColor = UIColor.white 
} 

override func viewDidLoad() { 

    super.viewDidLoad() 

    MainScrollView = UIScrollView() 
    MainScrollView?.isScrollEnabled = true 
    MainScrollView?.indicatorStyle = .default 
    MainScrollView?.contentSize = CGSize(width:self.view.bounds.width, height: 8000) 
    MainScrollView?.backgroundColor = UIColor.purple 

    setupViews() 
} 

    func setupViews(){ 

    view.addSubview(MainScrollView!) 
    MainScrollView?.addSubview(viewForScrollview) 

    viewForScrollview.addSubview(shopImage) 
    viewForScrollview.addSubview(shopNameandAddresView) 
    viewForScrollview.addSubview(timePaymentDetail) 

    addConstraintsWithFormat("H:|-0-[v0(414)]-0-|", views: MainScrollView!) 
    addConstraintsWithFormat("V:|-0-[v0(8000)]", views: MainScrollView!) 

    addConstraintsWithFormat("H:|-0-[v0(414)]-0-|", views: viewForScrollview) 
    addConstraintsWithFormat("V:|-0-[v0(8000)]", views: viewForScrollview) 


    addConstraintsWithFormat("V:|-0-[v0(1000)]-0-[v1(1000)]", views: shopImage,shopNameandAddresView) 
    addConstraintsWithFormat("H:|-0-[v0]-0-|", views: shopImage) 
    addConstraintsWithFormat("H:|-0-[v0]-0-|", views: shopNameandAddresView) 



} 


} 

Antwort

2

Verwendung als diese

override func viewDidLayoutSubviews() 
{ 
    MainScrollView?.contentSize = CGSize(width:self.view.bounds.width, height: 8000) 
} 
0

Es scheint, wie das in viewDidLoad Layout nicht beendet ist, so wird nicht die Scroll bewegen, weil es keinen richtiger Content versuchen hat als

die Content in ViewWillAppear Einstellung
MainScrollView?.contentSize = CGSize(width:self.view.bounds.width, height: 8000)