I've disabled all my auto layout, but it still won't scroll. I have many UIButtons on it and they are all linked to a Segue to be clicked so it can lead to the next page. I haven't added any code for the UIScrollView, and I'm not sure if you do or not. Here's a screenshot and the code I have for the scrollview scene,
@IBAction func derecourtButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func myburghButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func edmondsonButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func healyButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func bormansButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func jackwaysButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func horrackButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func mchughButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func youngButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func mitchellButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func testerButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func parrButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
@IBAction func holdenButton(_ sender: Any) {
self.performSegue(withIdentifier: "classtoperiod", sender: self)
}
Here's the screenshot of the main.storyboard: http://i.imgur.com/IPO3u0n.png
EDIT: I also need each button to have a value like an email, as it will send an email to whoever you select on the menu. Say you select maths, it will set the email recipient to "mathteacher@gmail.com" and so on.
Try this :
override func viewDidLayoutSubviews() {
scrollView.scrollEnabled = true
scrollView.contentSize = CGSizeMake(scrollview's width, 2300) // height should be grater than scrollview's frame height
}
Write Below code to start your scroll and check first that you delegate that scrollView, if not then first delegate it.
By writting code in viewDidLoad()
like this :
scrollView.delegate = self
and then add below code to set your view size into the scrollView.Yet we given default size as 700 => height,but after you check it's working then set yourViewName.contentSize
in height of the scrollView.ContentSize
Write this code in viewWillAppear()
or viewDidLayoutSubviews()
static scroll Height :
scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: 700)
Dynamic Scroll Height :
scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: yourViewName.frame.size.height)
may this help you.
Of course it won't scroll. Your scrollView doesn't know what its contentSize is (I assume it's [0,0] now based on your setup), therefore it will just behave like a normal UIView.
That's why when working with UIScrollView on Storyboard, you should ALWAYS consider using autolayout and setting the proper constraints. It's a little tricky at first, but once you've understood the mechanism, you'll love it.
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.