2012-09-24 13 views
14

में उन्मुखीकरण का समर्थन नहीं मैं इस कोड का उपयोग कर रहाpresentViewController IOS 6

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) 
    { 
     [self presentViewController:navigationControllerCustom animated:YES completion:nil]; 
    } 
    else 
    { 
     [self presentModalViewController:navigationControllerCustom animated:YES]; 
    } 

मेरा आवेदन दो उन्मुखीकरण पोर्ट्रेट और उल्टा पोर्ट्रेट है। इस कोड को आईओएस 5.1 के साथ अच्छी तरह से काम करता है, लेकिन उन्मुखीकरण मेरी navigationControllerCustom वर्ग पर iOS 6

मैं भी इस कोड को शामिल किया है पर काम नहीं करता

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown); 
} 

कृपया मेरी मदद इस समस्या को हल करने के लिए।

अग्रिम धन्यवाद।

+2

आईव IOS 6 के लिए संकलित मेरे ऐप्स में एक ही समस्या है; सभी उन्मुखताएं UIInterfaceOrientationPortraitUpsideDown को छोड़कर काम करती हैं; यह अजीब है। – MrJre

+0

@MrJre इस पर एक ही समाधान वास्तव में अजीब है। –

उत्तर

25

आप आप आवेदन प्रतिनिधि में यह शामिल करना चाहिए:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

यह भी सुनिश्चित करें देखें नियंत्रक दोनों, निम्नलिखित है मेरे लिए ठीक काम करता है बनाते हैं।

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

प्रलेखन भी कहता है कि UINavigationController's, समर्थित झुकाव के लिए अपने शीर्ष दृश्य नियंत्रक क्वेरी नहीं है, हालांकि एक एप्पल डेवलपर फ़ोरम पर अधिक इंजीनियर तो कहा था ... ऐसा लगता है कि ऐसा नहीं है। इसलिए आप UINavigationController के लिए एक वर्ग जोड़ना चाहिए, यह एक मैं का उपयोग करें:

#import "UINavigationController+autorotate.h" 

@implementation UINavigationController (autorotate) 

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

@end 

अधिक जानकारी कैसे autorotate आईओएस पर काम करता है के लिए 6 check out this answer

+0

सही उत्तर, आपने मेरी समस्या हल की, धन्यवाद :-) –

+1

UINavigationController श्रेणी पर्याप्त थी। – Gujamin

+0

+1 ऐप प्रतिनिधि भाग बहुत उपयोगी था। –

2

आप भूल गया:

- (BOOL)shouldAutorotate { 
    return YES; 
} 
+0

आपके उत्तर के लिए धन्यवाद। मैंने जोड़ा, लेकिन यह काम नहीं कर रहा है, मुझे कोई और चीज याद आ रही है। –

+0

समर्थित इंटरफ़ेस ओरिएंटेशन के तहत अपनी Info.plist में, क्या आपके पास पोर्ट्रेट और पोर्ट्रेट ऊपर सूचीबद्ध है? – rocky

+0

हां, मैंने यह भी किया है, कोई और बात? –

1

बस पेस्ट है कि आपके कोड ऊपर स्निपेट कॉपी

@implementation UINavigationController (rotation) 
//temp hack for iOS6, this allows passing supportedInterfaceOrientations to child viewcontrollers. 
- (NSUInteger)supportedInterfaceOrientations { 
return [self.topViewController supportedInterfaceOrientations]; 
} 

@end 
1

यदि आप सभी व्यू कंट्रोलर के लिए रोटेशन को सक्षम या अक्षम करने की योजना बनाते हैं तो आपको UINavigationController को उपclass करने की आवश्यकता नहीं है। इसके बजाय उपयोग करें:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 

आपके ऐपडिलेगेट में।

आप मूल दस्तावेज़ देख नियंत्रकों पर आपके ऐप की पूरी झुकाव लेकिन अलग झुकाव का समर्थन करना चाहते हैं (उदाहरण के लिए UINavigationController ढेर) आप अपने माता पिता के दृश्य नियंत्रक में निम्न विधियों के साथ संयोजन में

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 

उपयोग करना चाहिए।

- (BOOL)shouldAutorotate 

और

- (NSUInteger)supportedInterfaceOrientations 

लेकिन आप एक ही नेविगेशन ढेर में विभिन्न बच्चों ViewControllers में विभिन्न उन्मुखीकरण सेटिंग है की योजना (मेरे जैसे) यदि आप नेविगेशन ढेर में वर्तमान ViewController जाँच करने के लिए की जरूरत है।

मैं अपने UINavigationController उपवर्ग में निम्नलिखित बना लिया है:

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    int interfaceOrientation = 0; 

    if (self.viewControllers.count > 0) 
    { 
     id viewController; 
     DLog(@"%@", self.viewControllers); 
     for (viewController in self.viewControllers) 
     { 
      if ([viewController isKindOfClass:([InitialUseViewController class])]) 
      { 
       interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
      } 
      else if ([viewController isKindOfClass:([MainViewController class])]) 
      { 
       interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
      } 
      else 
      { 
       interfaceOrientation = UIInterfaceOrientationMaskAllButUpsideDown; 
      } 
     } 
    } 
    return interfaceOrientation; 
} 

आप बच्चों ViewControllers प्रस्तुत दृश्य नियंत्रक आप किसी भी तरह क्या दृश्य नियंत्रक वर्तमान में नेविगेशन स्टैक में है अवरोधन चाहिए की रोटेशन सेटिंग से अब और नियंत्रित नहीं कर सकते के बाद से । तो मैंने यही किया :)। उम्मीद है की वो मदद करदे !

+0

धन्यवाद @codeFi, आपके सुझावों ने मेरी समस्याओं को ठीक किया। विभिन्न डिवाइस-अभिविन्यास समस्याओं के साथ आईओएस 5 से आईओएस 6 में माइग्रेट करते समय मैं काफी संघर्ष कर रहा हूं। आपने मेरा दिन बना दिया! –

1

उपवर्ग UINavigationController और shouldAutorotate और supportedInterfaceOrientations इस तरह ओवरराइड:

-(BOOL)shouldAutorotate 
{ 
    return self.topViewController.shouldAutorotate; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return self.topViewController.supportedInterfaceOrientations; 
} 

और अब आप नियंत्रित कर सकते हैं अपने उन्मुखीकरण प्रत्येक ViewController है। प्रत्येक व्यू कंट्रोलर में बस दो विधियों को ओवरराइड करें।

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