2

我有一个水平滚动视图,并且启用了分页选项。所以我在“水平”的 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)
4

1 回答 1

3

最初设置contentOffsetscrollViewWidth*2将水平滚动到两页:

scrollView.contentOffset = CGPointMake(scrollViewWidth*2,0)

并且您可以将值设置为您想要X水平滚动的任何值。

于 2016-06-09T10:29:22.140 回答