我有一个水平滚动视图,并且启用了分页选项。因此,我在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)

最佳答案

最初将contentOffset设置为scrollViewWidth*2,它将水平滚动到两页:

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

并且您可以将X值中的任意值设置为水平滚动。

10-08 05:49