AutoLayout이있는 UIScrollView가 스크롤되지 않습니다.

소 티리스 카니 라스

나는 같은 질문을 계속해서 보았고 각 질문은 같은 답을 얻었습니다. "마지막보기 bottomAnchor를 scrollView와 동일하게 설정해야 bottomAnchor확장됩니다."

글쎄요, 스크롤 뷰가 스크롤되지만 (스크롤 막대가 움직이는 것을 봅니다) 뷰가 스크롤되지 않습니다! 다음은 코드입니다.

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
    setupConstraints()
}

fileprivate func setupConstraints() {
    setupScrollViewConstraints()
    setupLogoImageViewConstraints()
    setupUsernameTextFieldConstraints()
    setupPasswordTextFieldConstraints()
    setupShowAndHideButtonConstraints()
    setupForgotPasswordButtonConstraints()
    setupLoginButtonConstraints()
    setupAccountLabelConstraints()

    let signInWithAppleButton = setupSignInWithAppleButton()
    setupLoginWithFacebookButtonConstraints(signInWithAppleButton)

    setupSignUpButtonConstraints()
    setupTermsOfUseButtonConstraints()
}

fileprivate func setupScrollViewConstraints() {
    scrollView.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        scrollView.topAnchor.constraint(equalTo: self.view.topAnchor),
        scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
        scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
        scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
    ])
}

fileprivate func setupLogoImageViewConstraints() {
    logoImageView.translatesAutoresizingMaskIntoConstraints = false
    
    if #available(iOS 11.0, *) {
        NSLayoutConstraint.activate([
            logoImageView.topAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.topAnchor, constant: 16),
            logoImageView.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
            logoImageView.widthAnchor.constraint(equalToConstant: 112),
            logoImageView.heightAnchor.constraint(equalToConstant: 112)
        ])
    }
    else {
        NSLayoutConstraint.activate([
            logoImageView.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 16),
            logoImageView.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
            logoImageView.widthAnchor.constraint(equalToConstant: 112),
            logoImageView.heightAnchor.constraint(equalToConstant: 112)
        ])
    }
}

fileprivate func setupUsernameTextFieldConstraints() {
    usernameTextField.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        usernameTextField.topAnchor.constraint(equalTo: logoImageView.bottomAnchor, constant: 16),
        usernameTextField.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
        usernameTextField.widthAnchor.constraint(equalToConstant: self.view.frame.width / 1.4),
        usernameTextField.heightAnchor.constraint(equalToConstant: 45)
    ])
}

fileprivate func setupPasswordTextFieldConstraints() {
    passwordTextField.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        passwordTextField.topAnchor.constraint(equalTo: usernameTextField.bottomAnchor, constant: 8),
        passwordTextField.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
        passwordTextField.widthAnchor.constraint(equalToConstant: self.view.frame.width / 1.4),
        passwordTextField.heightAnchor.constraint(equalToConstant: 45)
    ])
}

fileprivate func setupShowAndHideButtonConstraints() {
    showAndHideButton.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        showAndHideButton.leadingAnchor.constraint(equalTo: passwordTextField.trailingAnchor, constant: -30),
        showAndHideButton.trailingAnchor.constraint(equalTo: passwordTextField.trailingAnchor),
        showAndHideButton.centerYAnchor.constraint(equalTo: passwordTextField.centerYAnchor),
        showAndHideButton.heightAnchor.constraint(equalToConstant: 20)
    ])
}

fileprivate func setupForgotPasswordButtonConstraints() {
    forgotPasswordButton.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        forgotPasswordButton.topAnchor.constraint(equalTo: passwordTextField.bottomAnchor),
        forgotPasswordButton.leadingAnchor.constraint(equalTo: passwordTextField.leadingAnchor),
        forgotPasswordButton.trailingAnchor.constraint(equalTo: passwordTextField.trailingAnchor),
        forgotPasswordButton.heightAnchor.constraint(equalToConstant: 45)
    ])
}

fileprivate func setupLoginButtonConstraints() {
    loginButton.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        loginButton.topAnchor.constraint(equalTo: forgotPasswordButton.bottomAnchor, constant: 20),
        loginButton.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
        loginButton.widthAnchor.constraint(equalToConstant: 210),
        loginButton.heightAnchor.constraint(equalToConstant: 45)
    ])
}

fileprivate func setupAccountLabelConstraints() {
    accountLabel.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        accountLabel.topAnchor.constraint(equalTo: loginButton.bottomAnchor, constant: 40),
        accountLabel.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
        accountLabel.heightAnchor.constraint(equalToConstant: 45)
    ])
}

fileprivate func setupSignInWithAppleButton() -> UIControl? {
    if #available(iOS 13.0, *) {
        let signInWithAppleButton = ASAuthorizationAppleIDButton(type: .default, style: .white)
        
        signInWithAppleButton.addTarget(self, action: #selector(loginWithApple(_:)), for: .touchUpInside)
        signInWithAppleButton.cornerRadius = 12
        
        scrollView.addSubview(signInWithAppleButton)
        
        signInWithAppleButton.translatesAutoresizingMaskIntoConstraints = false
        
        NSLayoutConstraint.activate([
            signInWithAppleButton.topAnchor.constraint(equalTo: accountLabel.bottomAnchor, constant: 8),
            signInWithAppleButton.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
            signInWithAppleButton.widthAnchor.constraint(equalToConstant: 210),
            signInWithAppleButton.heightAnchor.constraint(equalToConstant: 45)
        ])
        
        return signInWithAppleButton
    }
    
    return nil
}

fileprivate func setupLoginWithFacebookButtonConstraints(_ signInAppleButton: UIControl?) {
    facebookButton.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        facebookButton.topAnchor.constraint(equalTo: signInAppleButton?.bottomAnchor ?? accountLabel.bottomAnchor, constant: 8),
        facebookButton.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
        facebookButton.widthAnchor.constraint(equalToConstant: 210),
        facebookButton.heightAnchor.constraint(equalToConstant: 45)
    ])
}

fileprivate func setupSignUpButtonConstraints() {
    signUpButton.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        signUpButton.topAnchor.constraint(equalTo: facebookButton.bottomAnchor, constant: 8),
        signUpButton.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
        signUpButton.widthAnchor.constraint(equalToConstant: 210),
        signUpButton.heightAnchor.constraint(equalToConstant: 45)
    ])
}

fileprivate func setupTermsOfUseButtonConstraints() {
    termsButton.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        termsButton.topAnchor.constraint(equalTo: signUpButton.bottomAnchor, constant: 8),
        termsButton.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
        termsButton.widthAnchor.constraint(equalToConstant: 210),
        termsButton.heightAnchor.constraint(equalToConstant: 50),
        termsButton.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor)
    ])
}

이 문제는 지금 며칠 동안 나를 미치게 만듭니다! 내가 무엇을 놓치고 있습니까?

DonMag

당신 logoImageView은 잘못된 장소로 제한되어 있습니다 ...

// constrain Top to scrollView contentLayoutGuide Top
//logoImageView.topAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.topAnchor, constant: 16),
logoImageView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor, constant: 16),

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

UIScrollView에 추가 할 때 UIButton이 스크롤되지 않습니다.

분류에서Dev

더 넓은 UIView가있는 UIScrollView가 스크롤되지 않음

분류에서Dev

UIScrollView가 스크롤되는 동안 UI 요소가 업데이트되지 않습니다.

분류에서Dev

UIScrollView 내의 UIView가 스크롤되지 않는 이유는 무엇입니까?

분류에서Dev

내 UIScrollView (일부 UIControl 포함)가 iOS 8에서 더 이상 스크롤되지 않습니다.

분류에서Dev

스크롤되지 않는 uiview의 uiscrollview

분류에서Dev

인터페이스 빌더의 UIScrollView가 스크롤되지 않음

분류에서Dev

ReportViewer 컨트롤 스크롤 이벤트가 시작되지 않았습니다.

분류에서Dev

UITableView가있는 UIScrollView는 스크롤 할 수 없습니다.

분류에서Dev

내가 무엇을 시도해도 UIScrollView가 스크롤되지 않습니다.

분류에서Dev

UIScrollView setContentOffset이 콘텐츠 크기 밖으로 스크롤되고 뒤로 물러나지 않습니다.

분류에서Dev

View Pager 및 Fragments가있는 Android 탭 레이아웃이 부드럽게 스크롤되지 않습니다.

분류에서Dev

CSS div 거터가 포함되지 않습니다. 스크롤 / 컨테이너

분류에서Dev

Tkinter 스크롤 막대가 스크롤되지 않습니다.

분류에서Dev

토글 버튼이있는 ListView가 부드럽게 스크롤되지 않습니다.

분류에서Dev

UIScrollView 컨트롤러가 완전히 스크롤되지 않음

분류에서Dev

UIScrollView는 WKWebView 콘텐츠를 렌더링 한 후 스크롤되지 않습니다.

분류에서Dev

JFrame JTable 열 이름이 표시되지 않고 스크롤 막대가 표시되지 않습니다.

분류에서Dev

UIScrollView : 아무것도 스크롤되지 않습니다.

분류에서Dev

Q : UIScrollView를 UIView에 추가했는데 scrollView가 스크롤되지 않는 경우

분류에서Dev

UIScrollView가 스크롤되지 않음 (스토리 보드)

분류에서Dev

WPF의 스크롤 가능한 텍스트 상자는 컨테이너보다 크기 때문에 스크롤되지 않습니다.

분류에서Dev

라이트 박스 오버레이가 Chrome 또는 Edge에서 아래로 스크롤되지 않습니다.

분류에서Dev

콘텐츠가 페이지 아래로 확장되면 HTML 본문이 스크롤되지 않습니다.

분류에서Dev

RichFaces extendedDataTable 스크롤바는 화면 크기가 조정될 때까지 표시되지 않습니다.

분류에서Dev

이온 함량 길이가 변경되면 스크롤바가 업데이트되지 않습니다.

분류에서Dev

UITextView 페이징 UIScrollView 내부 스크롤이 작동하지 않습니다.

분류에서Dev

프로그래밍 방식 UIScrollView는 스크롤을 원하지 않습니다.

분류에서Dev

양식이 스크롤되지만 스크롤바가 움직이지 않음

Related 관련 기사

  1. 1

    UIScrollView에 추가 할 때 UIButton이 스크롤되지 않습니다.

  2. 2

    더 넓은 UIView가있는 UIScrollView가 스크롤되지 않음

  3. 3

    UIScrollView가 스크롤되는 동안 UI 요소가 업데이트되지 않습니다.

  4. 4

    UIScrollView 내의 UIView가 스크롤되지 않는 이유는 무엇입니까?

  5. 5

    내 UIScrollView (일부 UIControl 포함)가 iOS 8에서 더 이상 스크롤되지 않습니다.

  6. 6

    스크롤되지 않는 uiview의 uiscrollview

  7. 7

    인터페이스 빌더의 UIScrollView가 스크롤되지 않음

  8. 8

    ReportViewer 컨트롤 스크롤 이벤트가 시작되지 않았습니다.

  9. 9

    UITableView가있는 UIScrollView는 스크롤 할 수 없습니다.

  10. 10

    내가 무엇을 시도해도 UIScrollView가 스크롤되지 않습니다.

  11. 11

    UIScrollView setContentOffset이 콘텐츠 크기 밖으로 스크롤되고 뒤로 물러나지 않습니다.

  12. 12

    View Pager 및 Fragments가있는 Android 탭 레이아웃이 부드럽게 스크롤되지 않습니다.

  13. 13

    CSS div 거터가 포함되지 않습니다. 스크롤 / 컨테이너

  14. 14

    Tkinter 스크롤 막대가 스크롤되지 않습니다.

  15. 15

    토글 버튼이있는 ListView가 부드럽게 스크롤되지 않습니다.

  16. 16

    UIScrollView 컨트롤러가 완전히 스크롤되지 않음

  17. 17

    UIScrollView는 WKWebView 콘텐츠를 렌더링 한 후 스크롤되지 않습니다.

  18. 18

    JFrame JTable 열 이름이 표시되지 않고 스크롤 막대가 표시되지 않습니다.

  19. 19

    UIScrollView : 아무것도 스크롤되지 않습니다.

  20. 20

    Q : UIScrollView를 UIView에 추가했는데 scrollView가 스크롤되지 않는 경우

  21. 21

    UIScrollView가 스크롤되지 않음 (스토리 보드)

  22. 22

    WPF의 스크롤 가능한 텍스트 상자는 컨테이너보다 크기 때문에 스크롤되지 않습니다.

  23. 23

    라이트 박스 오버레이가 Chrome 또는 Edge에서 아래로 스크롤되지 않습니다.

  24. 24

    콘텐츠가 페이지 아래로 확장되면 HTML 본문이 스크롤되지 않습니다.

  25. 25

    RichFaces extendedDataTable 스크롤바는 화면 크기가 조정될 때까지 표시되지 않습니다.

  26. 26

    이온 함량 길이가 변경되면 스크롤바가 업데이트되지 않습니다.

  27. 27

    UITextView 페이징 UIScrollView 내부 스크롤이 작동하지 않습니다.

  28. 28

    프로그래밍 방식 UIScrollView는 스크롤을 원하지 않습니다.

  29. 29

    양식이 스크롤되지만 스크롤바가 움직이지 않음

뜨겁다태그

보관