我已禁用所有自动布局,但仍然无法滚动。我上面有许多UIButton,它们都与一个被点击的Segue相关联,因此可以进入下一页。我还没有为UIScrollView添加任何代码,我不确定你是否这样做。这是一个截图和我对scrollview场景的代码,
@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)
}
这是main.storyboard的屏幕截图:http://i.imgur.com/IPO3u0n.png
编辑:我还需要每个按钮都有一个类似电子邮件的值,因为它会向您在菜单上选择的任何人发送电子邮件。假设您选择数学,它会将电子邮件收件人设置为" mathteacher@gmail.com"等等。
答案 0 :(得分:0)
试试这个:
override func viewDidLayoutSubviews() {
scrollView.scrollEnabled = true
scrollView.contentSize = CGSizeMake(scrollview's width, 2300) // height should be grater than scrollview's frame height
}
答案 1 :(得分:0)
编写下面的代码以启动滚动并首先检查您是否委派了scrollView,如果没有,则首先委托它。
通过像这样写viewDidLoad()
中的代码:
scrollView.delegate = self
然后添加以下代码将您的视图大小设置为scrollView.Yet我们将默认大小设置为700 =>高度,但在你检查它的工作后,然后在yourViewName.contentSize
的高度设置scrollView.ContentSize
将此代码写入viewWillAppear()
或viewDidLayoutSubviews()
静态滚动高度:
scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: 700)
动态滚动高度:
scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: yourViewName.frame.size.height)
这可能对你有所帮助。
答案 2 :(得分:0)
当然不会滚动。你的scrollView不知道它的contentSize是什么(我认为它现在基于你的设置是[0,0]),因此它的行为就像普通的UIView一样。
这就是为什么在Storyboard上使用UIScrollView时,你应该总是考虑使用autolayout并设置正确的约束。一开始有点棘手,但是一旦你理解了机制,你就会喜欢它。