0

Let say I have 3 images in the scroll view. Now I am able to scroll it horizontally in either way. However, when reached the image #3, how to allow it to continuous scroll to image #1.

    override func viewDidAppear(_ animated: Bool) {

        //allow scrolling even outside the scroll view
        view.addGestureRecognizer(scrollView.panGestureRecognizer)
        var contentWidth : CGFloat = 0.0
        let scrollWidth = scrollView.frame.size.width

        // append 3 images
        for x in 0...2 {
            let image = UIImage(named: "icon\(x).png")
            let ImageView = (UIImageView(image:image))
            images.append(ImageView)

            var newX : CGFloat = 0.0
            newX = scrollWidth/2 + scrollWidth * CGFloat(x)

            scrollView.addSubview(ImageView)

//set the position of the image to center of the screen
            ImageView.frame = CGRect(x: newX - 75, y: (scrollView.frame.size.height/2)-75, width: 150, height: 150)

            contentWidth += newX

        }
        scrollView.clipsToBounds = false
        scrollView.contentSize = CGSize(width: contentWidth, height: view.frame.size.height)
    }
JiaWei Lee
  • 37
  • 1
  • 9

0 Answers0