7

यह एक अवलोकन भी चीज से ज्यादा है, क्योंकि मैं एक काम के आसपास पाया है दिखाई देते हैं ...[UIDevice currentDevice] .orientation == UIDeviceOrientationUnknown निम्नलिखित UINavigationController धक्का

कोड नीचे काम करने के लिए जब क्या है विफल रहता है एक नियंत्रक जिसे UINavigationController स्टैक पर धक्का दिया गया है। इस स्थिति में [UIDevice currentDevice].orientation लगातार UIDeviceOrientationUnknown देता है।

-(void)layoutAccordingToOrientation { 
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; 
    NSLog(@"layoutAccordingToOrientation/orientation==%i", orientation); 
    if (UIInterfaceOrientationIsLandscape(orientation)) { 
     : 
     _detailToolbar.frame = CGRectMake(0, 660, 1024, 44); 
    } else { 
     : 
     _detailToolbar.frame = CGRectMake(0, 916, 768, 44); 
    } 
} 

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [self layoutAccordingToOrientation]; 
} 

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

निम्नलिखित कॉल किया गया है:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
if (UIInterfaceOrientationIsLandscape(orientation)) { 
    etc. 
} else { 
    etc. 
} 

... जो काम करता है:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

इस UIDeviceOrientationUnknown -problem हल करने के लिए, मैं अब के बजाय निम्न का उपयोग हर बार।

फिर भी, मैं यह देखने में असफल रहा कि पहले बदलाव क्यों धक्का दृश्य नियंत्रक के संदर्भ में काम नहीं करेगा। विचार किसी को भी? क्या यह बस एक बग है?

+0

मुझे एक ही समस्या है, हालांकि मैं अपनी स्थिति में काम करने के लिए अपने काम को पाने में सक्षम नहीं हूं। – Flea

उत्तर

3

मैं यहाँ चीजों की एक जोड़ी के बारे में सोच सकता है, लेकिन मुझे यकीन है कि वे आप के लिए ...

सबसे पहले, जब अनुप्रयोग शुरू की है, आम तौर पर डिवाइस अभिविन्यास रिटर्न UIDeviceOrientationUnknown क्या देख रहे हैं नहीं कर रहा हूँ प्रदर्शन कारणों के लिए। एक चीज जिसे आप कोशिश कर सकते हैं, अपने सबव्यूव्स को .nib के अंदर या अपने स्टोरीबोर्ड में सही ऑटोरेज़िंग विकल्पों के साथ लेआउट करना है, और आईओएस को इसकी बात करने दें।

दूसरा, अगर आप मेरे जैसे हैं, तो हो सकता है कि आप किसी ऐसे डिवाइस पर परीक्षण कर रहे हों जो आपके कंप्यूटर के बगल में है, टेबल पर डालना। खैर, उस स्थिति में, आप UIDeviceOrientationUnknown चीज़ प्राप्त करने जा रहे हैं। आपको वास्तव में UIDeviceOrientationIsValidInterfaceOrientation([[UIDevice currentDevice] orientation]) के लिए परीक्षण करना चाहिए। यदि डिवाइस अपनी पीठ पर बिछा रहा है, उदाहरण के लिए, यह उस कथन में हाँ देता है। इसका यह भी अर्थ है कि जब आप UIInterfaceOrientationIsLandscape(orientation) का उपयोग करते हैं, तो आपको गलत कारण के लिए सही परिणाम मिल रहा है। UIInterfaceOrientationIsLandscape झूठी वापसी नहीं कर रहा है क्योंकि डिवाइस का अभिविन्यास UIDeviceOrientationPortrait है, लेकिन क्योंकि यह अमान्य है।

यह सुनिश्चित नहीं है कि इससे मदद मिली है, लेकिन मुझे यह समझने में थोड़ी देर लग गई और मैंने सोचा कि यह जानकारी साझा करना अच्छा होगा! :)

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