Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigationController에 ViewController를 여러개 추가시 background변화 #586

Open
eomiso opened this issue Oct 11, 2021 · 1 comment
Labels
iOS iOS 관련 내용 question 질문으로 사용될 이슈

Comments

@eomiso
Copy link
Collaborator

eomiso commented Oct 11, 2021

Simulator Screen Recording - iPhone 12 Pro Max - 2021-10-10 at 21 25 18

요약

NavigationController에 .pushViewController 함수로 VC를 추가할 때 왜 첫VC에는 background color가 default로 white이고 두번째 VC 는 color가 없는 것인가요?

첫번째 VC 는 navigation controller가 뒤에 있어서 navigation Controller의 background가 white인게 그대로 투과되어서 보이는 것이고, 두번 째 VC는 그 밑에 첫번째 VC가 깔려있어서 background가 없는게 되는 것인가요?

코드

import UIKit

class MainViewController: UIViewController {
    
    private let button = UIButton()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        title = "Waffle"
        //view.backgroundColor = .white
        
        setButton()
        
        print(navigationController ?? "No navigationController")
    }
    
    func setButton() {
        view.addSubview(button)
        button.setTitle("Press for adding Congroller", for: .normal)
        button.setTitleColor(.systemOrange, for: .normal)
        button.frame = CGRect(x: 100, y: 200, width: 300, height: 52)
        button.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)
    }
    
    @objc private func didTapButton() {
        let vc = MainViewController()
        print("adding vc to nc")
        navigationController?.pushViewController(vc, animated: true)
    }
}





@eomiso eomiso added iOS iOS 관련 내용 question 질문으로 사용될 이슈 labels Oct 11, 2021
@Ethan-MoBeau
Copy link
Contributor

저도 이건 왜 발생하는지 정확히 모르겠네요 ㅎㅎ...
아마 view hierarchy를 확인해보면 나올 것 같기는 한데....
일단 전에 진섭이형이 설명했듯이 navigation Controller는 자체의 뷰는 의미가 없고 그 아이가 들고있는 뷰가 실질적인 디자인을 맡아야합니다. 그래서 애시당초 저렇게 아무것도 세팅 안하고 그냥 push 하면 뷰컨트롤러가 뷰를 컨트롤안하고 있는거니 어폐가 있는게 맞아요

그래서 navigationController는 navigationBar 디자인 제외하고는 보통 그냥 background color를 clear로 둡니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS iOS 관련 내용 question 질문으로 사용될 이슈
Projects
None yet
Development

No branches or pull requests

2 participants