希望您能给我一些指导。我有一个垂直分页的ScrollView设置。我的问题是,视图比屏幕更大(垂直方向)。我的期望效果是将视图滚动到底部,然后翻到下一页,如下面的图片所示。
我尝试将ScrollView和内容大小设置为视图大小,这样可以正确地偏移视图。但我无法滚动并看到视图底部,它只会翻到下一页。
感谢任何建议。
我尝试将ScrollView和内容大小设置为视图大小,这样可以正确地偏移视图。但我无法滚动并看到视图底部,它只会翻到下一页。
感谢任何建议。
class ViewController: UIViewController {
let scrollView = UIScrollView() // Create the scrollView
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//Set up and add scrollView to view
scrollView.frame = self.view.frame
self.scrollView.pagingEnabled = true
self.view.addSubview(scrollView)
//An array of UIColors to add to the views
let x : [UIColor] = [UIColor.blueColor(),UIColor.redColor(),UIColor.yellowColor()]
//For each UIColor add a view that is 100px larger then the height of the scrollView
for index in 0...x.count-1{
//
let subView = UIView(frame: CGRectMake(
0, //x offset
(self.scrollView.frame.height + 100) * CGFloat(index), //y offset
self.scrollView.frame.width, // width
(self.scrollView.frame.height + 100))) // height
subView.backgroundColor = x[index] //background Color
scrollView.addSubview(subView) // Add View
}
//
let c = (self.scrollView.frame.size.height + 100) * CGFloat(x.count)
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.width, c)
//Background Color
self.view.backgroundColor = UIColor.greenColor()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}