Thursday, May 9, 2024
HomeiOS Developmentios - Web page UIScrollview merchandise one by one

ios – Web page UIScrollview merchandise one by one


I am attempting to imitate the scrolling expertise of iOS Digicam app choices (video, photograph, portrait, and so forth). When scrolling, the digital camera choices web page solely one by one.

enter image description here

Thus far that is what I’ve. As you may see within the demo under the paging stops on multiples of the scroll view’s bounds when the consumer scrolls and never just like the Digicam app.

class ViewController: UIViewController {
    lazy var stackView: UIStackView = {
        let stackView = UIStackView()
        stackView.axis = .horizontal
        stackView.spacing = 50
        return stackView
    }()
    
    lazy var scrollView: UIScrollView = {
        let scrollView = UIScrollView()
        scrollView.isPagingEnabled = true
        return scrollView
    }()
    
    let choices = ["Time-lapse", "Slo-Mo", "Cinematic", "Video", "Photo", "Portrait", "Pano"]
    
    override func loadView() {
        let view = UIView()
        self.view = view
        view.backgroundColor = .white
        view.addSubview(scrollView)
        scrollView.addSubview(stackView)

        scrollView.translatesAutoresizingMaskIntoConstraints = false
        scrollView.topAnchor.constraint(equalTo: view.topAnchor, fixed: 100).isActive = true
        scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
        scrollView.heightAnchor.constraint(equalToConstant: 50).isActive = true

        stackView.translatesAutoresizingMaskIntoConstraints = false
        stackView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
        stackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor).isActive = true
        stackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor).isActive = true
        stackView.heightAnchor.constraint(equalTo: scrollView.heightAnchor).isActive = true
        
        for choice in choices {
            let label = UILabel()
            label.textual content = choice.uppercased()
            stackView.addArrangedSubview(label)
        }
        
        scrollView.contentInset = UIEdgeInsets(prime: 0, left: UIScreen.fundamental.bounds.width/2, backside: 0, proper: UIScreen.fundamental.bounds.width/2)
    }
}

enter image description here

How do I repair this?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments