2012-10-02 9 views
28

यह त्रुटि मतलब नहीं है लौटना चाहिए पसंदीदा अभिविन्यास UIInterfaceOrientationLandscapeRight समर्थित उन्मुखीकरणpreferredInterfaceOrientationForPresentation, एक समर्थित इंटरफ़ेस उन्मुखीकरण

//iOS6 

-(BOOL)shouldAutorotate 
{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft); 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

त्रुटि द्वारा दिया जाता है के रूप में:

समाप्त एप्लिकेशन न आया हुआ अपवाद के कारण 'UIAplplicationInvalidInterfaceOrientation', कारण: 'पसंदीदा इंटरफेसऑरिएंटेशन फॉर प्रस्तुति को एक समर्थित इंटरफ़ेस अभिविन्यास वापस करना होगा!'

उत्तर

52

आपका कोड इस तरह दिखना चाहिए: इसके अलावा

-(BOOL)shouldAutorotate 
{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

, में सुनिश्चित करें कि आपके Info.plist आप के लिए सही झुकाव निर्धारित किया है आप ऐप क्योंकि supportedInterfaceOrientations से आप जो भी लौटते हैं उसे Info.plist से अलग किया जाता है और यदि यह सामान्य नहीं मिल पाता है तो आपको वह त्रुटि मिल जाएगी।

+0

मुझे यह दुख होने के कारण मिल रहा है! मेरे पास एक सार्वभौमिक ऐप साझा करने वाला व्यू कंट्रोलर कोड है और उपयोगकर्ता मुहावरे के लिए उपरोक्त कोड परीक्षण का उपयोग करें। आईपैड को केवल लैंडस्केप और सभी बार के लिए आईफोन पोर्ट्रेट होना चाहिए, जिसे परिदृश्य होना चाहिए। मैं – user7865437

+3

पर सही उन्मुखीकरण देने के लिए यह नहीं प्राप्त कर सकता हूं ध्यान दें कि यह "UIInterfaceOrientationMaskLandscape" का "मास्क" हिस्सा है जो इस उत्तर का महत्वपूर्ण हिस्सा है। मूल पोस्टर उपयोगकर्ता अपनी विधि में गलत enum। ऐसा लगता है कि ऐप्पल ने इस विधि के लिए enum/विकल्पों का एक नया सेट बनाया है जिससे लोगों को यह आसान त्रुटि मिलती है - इसके अतिरिक्त एक्सकोड किसी भी कंपाइलर समय की जांच भी प्रदान नहीं करता है क्योंकि विधि NSUInteger लौटाती है। –

+1

@ एलएमएस, मेरा पूरा एप्लिकेशन केवल एक दृश्य को छोड़कर पोर्ट्रेट मोड के लिए समर्थन करना चाहिए (जिसे लैंडस्केप के लिए समर्थन करने की आवश्यकता है)। प्लिस्ट में मैंने पोर्ट्रेट के लिए केवल उन्मुखीकरण निर्धारित किया है और मैंने कोड के ऊपर लिखा है जहां मैं लैंडस्केप के लिए अभिविन्यास बदलना चाहता हूं। लेकिन यह या तो UIInterfaceOrientationLandscapeRight या UIInterfaceOrientationLandscapeLeft दे रहा है। लेकिन मैं अपने विचार में दोनों चाहता हूं। क्या आप मुझे बता सकते हैं कि मैं इसे कैसे प्राप्त कर सकता हूं। –

8

supportedInterfaceOrientations के लिए वे गलत मानदंड हैं। आप, आदि (टिप्पणी शब्द बीच में मुखौटा) UIInterfaceOrientationMaskLandscapeLeft उपयोग करने की आवश्यकता

14

supportedInterfaceOrientations केवल, कहा जाता है यदि shouldAutorotate हां में

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

मेरे लिए सबसे आसान दृष्टिकोण सेट कर दिया जाता है, तो आप का समर्थन करना चाहते हैं Info.plist

info.plist

स्थापित करने के लिए ही है आईओएस 5 आपके कोड नियंत्रकों में इस कोड का उपयोग करें।

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 
1

प्रलेखन से:

-(NSUInteger)supportedInterfaceOrientations { 

    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft; 
} 

ध्यान दें कि सही ओरिएंटेशन "मास्क" है! क्या आपने इसे आजमाया?

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