मेरे पास एक व्यू कंट्रोलर है जो एक कस्टम व्यू का मालिक है; कस्टम व्यू कोर ग्राफिक्स का उपयोग कर एक गेम बोर्ड खींचता है। (कोई अन्य सबव्यू शामिल नहीं हैं।)मॉड्यूल (ऑटो लेआउट का उपयोग करके) प्रस्तुत करते समय मेरा पर्यवेक्षण-सब-सबव्यू क्यों छोटा हो जाता है?
मैंने ऑटो लेआउट बाधाओं को स्थापित किया ताकि गेम बोर्ड इसके पर्यवेक्षण को भर सके। जब मैं दृश्य नियंत्रक को रूट व्यू कंट्रोलर के रूप में सेट करता हूं, तो गेम बोर्ड (और पर्यवेक्षक) स्क्रीन को भरता है, जैसा कि मेरा इरादा है। हालांकि, जब मैं व्यू कंट्रोलर को सामान्य रूप से प्रस्तुत करता हूं, तो गेम बोर्ड (और पर्यवेक्षण) कुछ भी न्यूनतम/न्यूनतम नहीं होता है, और ऑटो लेआउट ट्रेस रिपोर्ट लेआउट अस्पष्ट है।
मैंने प्रश्न को स्पष्ट करने के लिए एक सरल परीक्षण केस लिखा था।
यहां मेरा BoardViewController
है, जिसमें एक हरे रंग की पृष्ठभूमि के साथ एक शीर्ष-स्तरीय दृश्य है, लेकिन एक लाल पृष्ठभूमि के साथ एक विशाल विस्तृत सबव्यू बनाता है। मैं स्क्रीन सभी लाल को देखने के लिए जब इस दृश्य नियंत्रक कार्यभार संभाला चाहते हैं:
- (void)loadView
{
UIView *mainView = [[UIView alloc] init];
mainView.translatesAutoresizingMaskIntoConstraints = NO;
mainView.backgroundColor = [UIColor greenColor];
UIView *subView = [[UIView alloc] init];
subView.translatesAutoresizingMaskIntoConstraints = NO;
subView.backgroundColor = [UIColor redColor];
[mainView addSubview:subView];
self.view = mainView;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(subView);
NSArray *c1 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[subView(>=10)]|"
options:0
metrics:nil
views:viewsDictionary];
NSArray *c2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[subView(>=10)]|"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:c1];
[self.view addConstraints:c2];
}
अगर मैं अपने रूट दृश्य नियंत्रक के रूप में सेट है, तो मैं अपने अच्छा लाल खेल बोर्ड स्क्रीन भरने देखें। हालांकि, खेल बोर्ड न्यूनतम 10x10 वर्ग के लिए सिकुड़ जाता है जब मैं एक अलग RootViewController
से BoardViewController
मौजूद:
- (void)loadView
{
UIView *rootView = [[UIView alloc] init];
rootView.translatesAutoresizingMaskIntoConstraints = NO;
UIButton *presentButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
presentButton.translatesAutoresizingMaskIntoConstraints = NO;
[presentButton setTitle:@"Present" forState:UIControlStateNormal];
[presentButton addTarget:self
action:@selector(present:)
forControlEvents:UIControlEventTouchUpInside];
[rootView addSubview:presentButton];
self.view = rootView;
[rootView addConstraint:[NSLayoutConstraint constraintWithItem:presentButton
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:rootView
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0.0]];
[rootView addConstraint:[NSLayoutConstraint constraintWithItem:presentButton
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:rootView
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0.0]];
}
- (void)present:(id)sender
{
BoardViewController *bvc = [[BoardViewController alloc] init];
[self presentViewController:bvc animated:YES completion:NULL];
}
मैं अलग ऑटो लेआउट नियमों की कोशिश कर रखना है, लेकिन कोई फर्क नहीं पड़ता कि मुझे क्या करना है, मैं खेल नहीं मिल सकता है जब स्क्रीन नियंत्रक को सामान्य रूप से प्रस्तुत किया जाता है तो स्क्रीन को भरने के लिए बोर्ड। (साथ ही मैं इस सवाल से पूछ रहा हूं, मैं रनटाइम प्राप्त करने की कोशिश कर रहा हूं कि मुझे यह बताने के लिए कि क्या लगता है वह अस्पष्ट है। लेकिन मैं अभी भी यह डिबगिंग बहुत अच्छा नहीं हूं, इसलिए मेरा प्रश्न यहां है।)
शानदार! धन्यवाद! तो, स्पष्टीकरण: मैं अपने शीर्ष-स्तर के दृश्य के लेआउट के साथ गलत तरीके से गड़बड़ कर रहा था, जो कि मुझे प्रस्तुत करने का अधिकार है। इस मामले में, 'presentViewController: एनिमेट: समापन:' (हम मानते हैं) स्प्रिंग्स-एंड-स्ट्रेट्स का उपयोग करके अपने विचार जोड़ता है, इसलिए मैंने इसे तोड़ दिया। क्या यह कहने का एक उचित तरीका है? –
जो मैं देख सकता हूं उससे ऐसा लगता है कि खिड़की के 'रूट व्यू कंट्रोलर' होने का एक विशेष मामला है जो बाधाओं को दूर करता है।अगर आप 'mainView.translatesAutoresizingMaskIntoConstraints = NO;' में छोड़ते हैं तो क्या होगा, इसके साथ प्रयोग करना दिलचस्प होगा और कुछ बाधाओं को मैन्युअल रूप से जोड़ने के लिए 'अपडेट कॉन्स्ट्रेनेंट्स' को लागू करें ... –
मैंने '[self.view translatesAutoresizingMaskIntoConstraints] 'के मान को डंप करने का प्रयास किया। 'viewDidAppear: 'दोनों मोडल प्रस्तुति और सेट-ए-रूट-व्यू-कंट्रोलर के लिए। दोनों मामलों में यह हां बाहर निकल गया। शायद रूट व्यू कंट्रोलर के रूप में एक दृश्य सेट करना स्पष्ट रूप से अपने फ्रेम को सेट करता है, जबकि एक व्यू कंट्रोलर प्रस्तुत नहीं करता है। –