简体   繁体   中英

Swift scrollview adding from XIB not scrollable at all

I'm trying to import from Xib full screen ScrollView into my ViewController.

Following that guide i've made many working examples of it, but when importing it from Xib, ScrollView not responding on scroll (not even bouncing)

My Xib View class:

class TestScroll: UIView {

override init(frame: CGRect) {
    super.init(frame: frame)
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

override func awakeFromNib() {
    super.awakeFromNib()

    self.translatesAutoresizingMaskIntoConstraints = false
}

public static func getViewFromNib() -> TestScroll {
    return UINib(nibName: "TestScroll", bundle: .main).instantiate(withOwner: nil, options: nil).first as! TestScroll
    }
}

And this is how i adding it in ViewController:

override func viewDidLoad() {
    super.viewDidLoad()

    let testScroll = TestScroll.getViewFromNib()
    self.view.addSubview(testScroll)
}

Please help, i've checked many guides already, but not found working example with Xib.

You need to set a frame / constraints

let testScroll = TestScroll.getViewFromNib()
testScroll.frame = self.view.bounds
self.view.addSubview(testScroll)

leave this

self.translatesAutoresizingMaskIntoConstraints = false

only if you'll set constraints

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM