希望您可以在此给我一些指导。我有一个垂直分页的滚动视图设置。我的问题是视图大于屏幕(垂直)。我希望的效果是让视图滚动到底部,然后翻到下一页。就像我下面的图片试图描绘的一样。在垂直分页启用的情况下在UIScrollView中垂直滚动
我已经尝试将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.
}
}
你的意思是垂直的,对吧? – rdelmar 2014-11-01 03:59:57
* Facepalm *。是的我的意思是垂直。固定 – User4 2014-11-01 04:01:06
大小总是需要保持屏幕大小,并且您需要根据图像数量设置contentSize,如果帧和内容都相同,那么它将如何滚动。 – Balu 2014-11-01 05:18:07