पर UIScrollView के शीर्ष पर गैप मुझे UIScrollView पर बाधाओं के साथ कोई समस्या है जो आईओएस 10-विशिष्ट प्रतीत होता है। मुझे स्क्रॉल व्यू के शीर्ष और अंदर के सामग्री दृश्य के बीच एक अंतर दिखाई देता है, जिसे शीर्ष पर अटक जाना चाहिए।आईओएस 10
आईओएस 9 पर कोई अंतर नहीं दिखता है, लेकिन आईओएस 10 पर अंतर दिखाई देता है।
स्पष्ट होने के लिए, दोनों स्थितियों में स्क्रॉल व्यू टॉप शीर्ष लेआउट मार्गदर्शिका के नीचे पिन किया गया है, जो नेविगेशन बार के नीचे से पूरी तरह से लाइनों के साथ लाइनें हैं। आईओएस 10 स्क्रॉल व्यू के शीर्ष और सामग्री दृश्य के शीर्ष के बीच नेविगेशन बार का आकार एक अंतर पेश करता है।
मैं शीर्ष लेआउट मार्गदर्शिका के शीर्ष पर स्क्रॉल व्यू के शीर्ष को संरेखित कर सकता हूं, जो नेविगेशन बार के नीचे का अंतर रखेगा और सामग्री दृश्य ठीक हो जाएगा, लेकिन आईओएस 9 पर सामग्री दृश्य नीचे होगा नेविगेशन बार जो अवांछित है।
मैंने जल्दी से कुछ खेल का मैदान कोड बनाया है जो नीचे दिए गए मुद्दे को प्रदर्शित करता है। क्या मुझे कुछ याद आ रही है? यह एक मुद्दा बनाने के लिए आईओएस 10 में क्या बदल गया, और मैं इसके आसपास कैसे काम करूं?
import UIKit
import PlaygroundSupport
class TestViewController: UIViewController {
var mainScrollView: UIScrollView
var contentView: UIView
init() {
self.mainScrollView = UIScrollView()
self.contentView = UIView()
super.init(nibName: nil, bundle: nil)
self.view.backgroundColor = UIColor.white
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
self.mainScrollView.backgroundColor = UIColor.green
self.contentView.backgroundColor = UIColor.blue
self.mainScrollView.translatesAutoresizingMaskIntoConstraints = false
self.contentView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.mainScrollView)
self.mainScrollView.addSubview(self.contentView)
// constrain the scroll view bounds to the view
self.view.addConstraint(NSLayoutConstraint(item: self.mainScrollView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.topLayoutGuide, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: self.mainScrollView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.bottomLayoutGuide, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: self.mainScrollView, attribute: NSLayoutAttribute.leading, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.leading, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: self.mainScrollView, attribute: NSLayoutAttribute.trailing, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.trailing, multiplier: 1, constant: 0))
// constrain the content view bounds to the scroll view
self.mainScrollView.addConstraint(NSLayoutConstraint(item: self.contentView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.mainScrollView, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0))
self.mainScrollView.addConstraint(NSLayoutConstraint(item: self.contentView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.mainScrollView, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0))
self.mainScrollView.addConstraint(NSLayoutConstraint(item: self.contentView, attribute: NSLayoutAttribute.leading, relatedBy: NSLayoutRelation.equal, toItem: self.mainScrollView, attribute: NSLayoutAttribute.leading, multiplier: 1, constant: 0))
self.mainScrollView.addConstraint(NSLayoutConstraint(item: self.contentView, attribute: NSLayoutAttribute.trailing, relatedBy: NSLayoutRelation.equal, toItem: self.mainScrollView, attribute: NSLayoutAttribute.trailing, multiplier: 1, constant: 0))
// constrain the content view's size to the view's size
self.view.addConstraint(NSLayoutConstraint(item: self.contentView, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.width, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: self.contentView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.greaterThanOrEqual, toItem: self.view, attribute: NSLayoutAttribute.height, multiplier: 1, constant: 0))
}
}
let rootViewController = TestViewController()
rootViewController.title = "Test"
let navigationController = UINavigationController(rootViewController: rootViewController)
PlaygroundPage.current.liveView = navigationController.view
मेरे पास एक ही समस्या है ... केवल आईओएस 10 में होती है। क्या आपके पास इसे तय करने में कोई भाग्य है? – inorganik
@inorganik - नहीं, अभी तक नहीं। प्रोजेक्ट के साथ आगे बढ़ने की तरह बस इसे छोड़ दें। एक ओएस संस्करण जांच में डाल दिया जा सकता है, जिसे मैं टालने की उम्मीद कर रहा हूं। –
मैंने जो समाधान पाया है, उसे जोड़ा गया है, उम्मीद है कि यह आपके लिए काम करता है। – inorganik