아래 코드로 실험 해보십시오. 이 일반적인 접근 방식은 내 프로젝트에서 작동합니다. 문제는 height 속성에 대한 모호한 정의입니다. .xib에서 불필요한 제약 조건을 찾는데주의하십시오.
@IBOutlet weak var yourCustomScrollView: UIScrollView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Firstly, define scrollview's position and size
yourCustomScrollView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
// Load .xib with custom class from main bundle.
guard let xib = Bundle.main.loadNibNamed("YourXibName", owner: self, options: nil)?.first as? YourCustomXibClass else {
fatalError("YourXibName is not found. ")
}
self.yourCustomScrollView.addSubView(xib)
// Define .xib's position and size
xib.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
yourCustomScrollView.contentSize = CGSize(width: self.view.frame.width, height: xib.frame.height)
}
어떤 Xcode 버전을 사용하고 있습니까? Apple은'Xcode 9 '에서 Auto Layout과 많은 관련이있었습니다. 질문을 업데이트 할 수 있다면 도움이 될 것입니다. – KSigWyatt
콘텐츠 뷰를 스크롤 뷰와 동일한 높이로 설정하는 제약 조건을 추가해보십시오. – RPK