मैंने कस्टम कंटेनर व्यू कंट्रोलर बनाने के साथ स्वयं को परिचित करने के लिए एक टेस्ट ऐप बनाया है। यदि ऐप पहली बार शुरू होता है या किसी भिन्न दृश्य नियंत्रक पर स्विच करने के बाद डिवाइस को घुमाता है, तो नया दृश्य पूरे स्क्रीन को लेने के लिए बदलता है, जैसा कि मैंने इरादा किया था। हालांकि, यदि ऐप शुरू होने के बाद मैं घूमता हूं, और उसके बाद एक नया दृश्य नियंत्रक पर स्विच करता है, तो दृश्य छोटे और व्यापक होने की बजाय अपने पोर्ट्रेट आकार को रखता है (वास्तव में यह थोड़ा अलग है - यह 320,460 से 300,480 तक जाता है)। मास्टर व्यू कंट्रोलर ऐप प्रतिनिधि (कोई xib) में init'd है और विंडो के रूट व्यू कंट्रोलर के रूप में सेट है। यहाँ कोड मैं अपने MasterViewController में है (कस्टम कंटेनर नियंत्रक) है:कस्टम कंटेनर नियंत्रक में रोटेशन के बाद आकार बदलने का विचार
- (void)viewDidLoad {
[super viewDidLoad];
WelcomeController *welcome = [[WelcomeController alloc] initWithNibName:@"ViewController" bundle:nil];
self.currentController = welcome;
[self addChildViewController:welcome];
[self.view addSubview:welcome.view];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
}
- (void)swipeLeft:(UISwipeGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateRecognized) {
UIActionSheet *sheet =[[UIActionSheet alloc] initWithTitle:@"Select A Destination" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"welcome",@"Play",@"Scores", nil];
[sheet showInView:self.view];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:{
if ([self.currentController class] != [WelcomeController class]) {
WelcomeController *welcome = [[WelcomeController alloc] initWithNibName:@"ViewController" bundle:nil];
[self addChildViewController:welcome];
[self moveToNewController:welcome];
}
break;
}
case 1:{
if ([self.currentController class] != [PlayViewController class]) {
PlayViewController *player = [[PlayViewController alloc] initWithNibName:@"PlayViewController" bundle:nil];
[self addChildViewController:player];
[self moveToNewController:player];
}
break;
}
case 2:{
if ([self.currentController class] != [HighScores class]) {
HighScores *scorer = [[HighScores alloc] initWithNibName:@"HighScores" bundle:nil];
[self addChildViewController:scorer];
[self moveToNewController:scorer];
}
break;
}
case 3:
NSLog(@"Cancelled");
break;
default:
break;
}
}
-(void)moveToNewController:(id) newController {
[self.currentController willMoveToParentViewController:nil];
[self transitionFromViewController:self.currentController toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{}
completion:^(BOOL finished) {
[self.currentController removeFromParentViewController];
[newController didMoveToParentViewController:self];
self.currentController = newController;
}];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;//(interfaceOrientation == (UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft));
}
कोई भी विचार क्यों यह (क्या हो रहा है, तो इसका मतलब है कि मास्टर दृश्य नियंत्रक के दृश्य का आकार बदलने नहीं है मैं नहीं जानता, लेकिन जब मुझे यह गैर-आकार देने वाला व्यवहार मिलता है तो इशारा पहचानकर्ता केवल संकीर्ण दृश्य में प्रतिक्रिया देता है, न कि पूरे स्क्रीन पर)?
मुझे पता चला कि अगर मैं एक xib फ़ाइल और alloc initWithNibName का उपयोग करता हूं: बंडल: केवल init के बजाय, यह सही ढंग से काम करता है। तो, ऐसा लगता है कि जब आप केवल इनिट करते हैं तो आपको यह देखने के लिए कुछ करना पड़ता है। जब मैं दृश्य को लॉग करता हूं, हालांकि, यह समान दिखता है कि सादे init या xib फ़ाइल से - दोनों में एक ही फ्रेम है और एक ही ऑटोरेसाइज = डब्ल्यू + एच – rdelmar
ऑटोरेसाइजिंग मास्क प्रोग्रामेटिक रूप से 'UIViewAutoresizingFlexibleWidth] को परिभाषित करता है। UIViewAutoresizingFlexibleHeight' – yasirmturk