我有一个水平滚动视图,我启用了分页选项。所以我在3页"水平"中添加了总共3个图像视图。我希望我的最后一页首先显示。即从右边开始。这是我的代码:
self.myScrollView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
let scrollViewWidth = self.myScrollView.frame.width
let scrollViewHeight = self.myScrollView.frame.height
let imgOne = UIImageView(frame: CGRectMake(0, 0, scrollViewWidth, scrollViewHeight))
let imgTwo = UIImageView(frame: CGRectMake(-(scrollViewWidth), 0, scrollViewWidth, scrollViewHeight))
let imgThree = UIImageView(frame: CGRectMake(-(scrollViewWidth)*2, 0, scrollViewWidth, scrollViewHeight))
imgOne.image = UIImage(named: "0")
imgTwo.image = UIImage(named: "1")
imgThree.image = UIImage(named: "2")
self.myScrollView.addSubview(imgOne)
self.myScrollView.addSubview(imgTwo)
self.myScrollView.addSubview(imgThree)
self.myScrollView.contentSize = CGSizeMake(scrollViewWidth*3, 0)
答案 0 :(得分:3)
最初将contentOffset
设置为scrollViewWidth*2
,它将水平滚动到两个页面:
scrollView.contentOffset = CGPointMake(scrollViewWidth*2,0)
并且您可以在X
值中设置所需的任何值以水平滚动。