2012-08-24 8 views
5

मैंने कस्टम कंटेनर व्यू कंट्रोलर बनाने के साथ स्वयं को परिचित करने के लिए एक टेस्ट ऐप बनाया है। यदि ऐप पहली बार शुरू होता है या किसी भिन्न दृश्य नियंत्रक पर स्विच करने के बाद डिवाइस को घुमाता है, तो नया दृश्य पूरे स्क्रीन को लेने के लिए बदलता है, जैसा कि मैंने इरादा किया था। हालांकि, यदि ऐप शुरू होने के बाद मैं घूमता हूं, और उसके बाद एक नया दृश्य नियंत्रक पर स्विच करता है, तो दृश्य छोटे और व्यापक होने की बजाय अपने पोर्ट्रेट आकार को रखता है (वास्तव में यह थोड़ा अलग है - यह 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)); 
} 

कोई भी विचार क्यों यह (क्या हो रहा है, तो इसका मतलब है कि मास्टर दृश्य नियंत्रक के दृश्य का आकार बदलने नहीं है मैं नहीं जानता, लेकिन जब मुझे यह गैर-आकार देने वाला व्यवहार मिलता है तो इशारा पहचानकर्ता केवल संकीर्ण दृश्य में प्रतिक्रिया देता है, न कि पूरे स्क्रीन पर)?

+3

मुझे पता चला कि अगर मैं एक xib फ़ाइल और alloc initWithNibName का उपयोग करता हूं: बंडल: केवल init के बजाय, यह सही ढंग से काम करता है। तो, ऐसा लगता है कि जब आप केवल इनिट करते हैं तो आपको यह देखने के लिए कुछ करना पड़ता है। जब मैं दृश्य को लॉग करता हूं, हालांकि, यह समान दिखता है कि सादे init या xib फ़ाइल से - दोनों में एक ही फ्रेम है और एक ही ऑटोरेसाइज = डब्ल्यू + एच – rdelmar

+0

ऑटोरेसाइजिंग मास्क प्रोग्रामेटिक रूप से 'UIViewAutoresizingFlexibleWidth] को परिभाषित करता है। UIViewAutoresizingFlexibleHeight' – yasirmturk

उत्तर

0

आप अपने बच्चे के दृश्य नियंत्रकों को रोटेशन संदेश नहीं भेज रहे हैं। आपके द्वारा पोस्ट किए गए कोड में कम से कम नहीं। चाइल्ड कंट्रोलर को स्विच करने के बाद आप पिछले बच्चे को चाइल्ड व्यू कंट्रोलर सरणी से [self.currentController removeFromParentViewController] से हटा रहे हैं, भले ही आप - (BOOL) को स्वचालित रूप से कार्यान्वित करें। फॉरवर्डएपियरेंस एंडरोटेशन मैथ्यूज टू चिल्डव्यू कंट्रोलर आपके पास हमेशा आपके माता-पिता दृश्य नियंत्रक में केवल एक चाइल्ड व्यू कंट्रोलर है।

मुझे यह काम मिल गया है, इसलिए मैं आपको पेस्ट कर दूंगा कि मैं यह कैसे कर रहा हूं। सबसे पहले मैं अपने सभी व्यू कंट्रोलर बना देता हूं, उन्हें पेरेंट व्यू कंट्रोलर को बाल दृश्य नियंत्रकों के रूप में जोड़ें। फिर कॉल किया गया हैमोवेटेंटिव्यू कंट्रोलर: विधि।

//Controller1 
Controller1 *c1 = [[Controller1 alloc] init]; 
c1.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
[self addChildViewController:c1]; 
[c1 didMoveToParentViewController:self]; 

//Controller2 
Controller2 *c2 = [storyboard instantiateViewControllerWithIdentifier:@"c2"]; 
index.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
[self addChildViewController:c2]; 
[c2 didMoveToParentViewController:self]; 
c2.view.frame = m_contentView.frame; 
[self.view addSubview:c2.view]; //It is in initial screen so set it right away 
m_selectedViewController = c2; 

//Controller3 
Controller3 *c3 = [storyboard instantiateViewControllerWithIdentifier:@"c3"]; 
compare.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
[self addChildViewController:c3]; 
[c3 didMoveToParentViewController:self]; 

m_controllers = [NSArray arrayWithObjects:c1, c2, c3, nil]; //Hmm now i think this is not needed, I can access viewController directly from self.childViewControllers array 

तब मैं

- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers 
{ 
    return YES; 
} 

कार्यान्वित बच्चे दृश्य नियंत्रक पर स्विच किया इस कोड

if (value < m_controllers.count) 
{ 
    UIViewController *contentViewController = [m_controllers objectAtIndex:value]; 

    contentViewController.view.frame = m_contentView.frame; 

    [self transitionFromViewController:m_selectedViewController toViewController:contentViewController duration:0 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) { 
     m_selectedViewController = contentViewController; 
     } 
    ]; 
} 

यह enought किया जाना चाहिए के साथ किया जाता है। लेकिन मुझे इसके साथ कुछ समस्याएं हैं इसलिए मैं अपने आप को निष्क्रिय बच्चों को रोटेशन संदेश भेजता हूं।

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    for (UIViewController *vc in m_controllers) 
    { 
     if(vc != m_selectedViewController) 
      [vc willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
    } 
} 

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    for (UIViewController *vc in m_controllers) 
    { 
     if(vc != m_selectedViewController) 
      [vc willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
    } 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    for (UIViewController *vc in m_controllers) 
    { 
     if(vc != m_selectedViewController) 
      [vc didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    } 
} 
+0

स्वचालित रूप से ForwardAppearanceAndRotationMethodsToChildViewController को आईओएस 6 में गिरा दिया गया है, जिसे बदलना चाहिए स्वचालित रूप सेForwardRotationMethods। लेकिन, आपको इसे लागू करने की आवश्यकता नहीं है क्योंकि डिफ़ॉल्ट हाँ है। तो, यह समस्या नहीं है। जैसा कि मैंने प्रश्न पर मेरी टिप्पणी में उल्लेख किया है, मुझे पहले ही मेरा जवाब मिला है। – rdelmar

0

मैन्युअल

- (void)viewDidLoad 

अंदर

जोड़ा गया है और यह समस्या किसी कारण स्टोरीबोर्ड के अंदर मान उपयोग नहीं किया जा रहा था मैं अनुमान

के लिए

हल

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^