2010-03-12 13 views
10

मैं एक व्यू/व्यू कंट्रोलर डिज़ाइन करना चाहता हूं जो परिदृश्य अभिविन्यास में स्वचालित रूप से एक सबव्यूव को दिखाता/छुपाता है। मैं अपनी जगह लेने के लिए सबवेव को पूरी तरह से गायब करने के लिए और अन्य सबव्यूज़ चाहता हूं।अभिविन्यास बदलते समय पूरी तरह से UIView को कैसे छिपाना है?

एक UIViewController का उपयोग करना, मैं कोड है कि subviews 'फ्रेम संपत्ति सेट करता है और पर इसे कहते लिखा है:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration; 

यह समस्या समय की सबसे को हल करती है, लेकिन समस्या है जब उन्मुखीकरण परिवर्तन हो रहा है जब दृश्य प्रकट नहीं हो रहा है इस बायपास करने के लिए, मैं भी पर आकार बदलने विधि बोल रहा हूँ:

- (void)viewWillAppear:(BOOL)animated; 

लेकिन यह कुछ दुर्लभ मामलों में समस्याओं (एक UISearchDisplayController शामिल) है तो मैं भी

- (void)viewDidAppear:(BOOL)animated; 

पर आकार बदलने विधि बोल रहा हूँ जैसा कि आप समझ सकते हैं, मैं इस कोड से नाखुश हूं और मैं ऐसा करने के लिए एक बेहतर/अधिक प्रदर्शन करने वाला तरीका ढूंढ रहा हूं।

कोई विचार?

+0

मैं इस प्रश्न पर एक उपहार प्रदान कर रहा हूं। मेरे मामले में, मुझे नीचे दिए गए विज्ञापन बैनर के साथ, मेरे दृश्य के केंद्र में UIWebView मिला है। मैं विज्ञापन बैनर को हटाना चाहता हूं और आकार बदलने पर लापता स्थान को भरने के लिए UIWebView आकार बदलना चाहता हूं। मैंने पर्यवेक्षण से बैनर को हटाने का प्रयास किया, लेकिन UIWebView खाली स्थान भरने के लिए आकार बदलता नहीं है (भले ही सभी ऑटोरेसाइजिंग मास्क सक्षम हैं)। –

उत्तर

0

अंदर

- (void)didRotateFromInterfaceOrientation: 
    (UIInterfaceOrientation)fromInterfaceOrientation 

यह

sub_view.hidden = YES; 

छिपाने के लिए फिर से

sub_view.hidden = NO; 
+1

आपकी प्रतिक्रिया के लिए धन्यवाद लेकिन छुपा संपत्ति सिर्फ दृश्य को छुपाती है। यह अपनी जगह लेने के लिए अन्य विचारों का आकार बदलता नहीं है। –

+0

ओह, आप यह करना चाहते हैं। क्या आपने चेक किया है यदि आप लेआउटस्यूब्यूव्यू और लेआउट का उपयोग कर सकते हैं IFNeeded? –

0

यह दिखाने के लिए कई subviews परिदृश्य और चित्र में बहुत अलग ढंग से बाहर रखा करने की आवश्यकता है देखते हैं, तो , आईबी में जोड़े गए, परिदृश्य दृश्य देखें, इसे अतिरिक्त UIView के साथ हैक करना आसान हो सकता है। बटन, सबव्यू इत्यादि के साथ इस दृश्य को लोड करें और अपनी पसंद के अनुसार इसे बाहर रखें। आप सामान्य (चित्र) दृश्य के साथ सभी समान कनेक्शन का उपयोग कर सकते हैं। शीर्षलेख में IBOutlet UIView *landscapeView; घोषित करना याद रखें। समय काम नहीं करता

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation 
           duration:(NSTimeInterval)duration 
{ 
    if ([landscapeView superview]) { 
     if (toOrientation == UIInterfaceOrientationPortrait || 
      toOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
      [landscapeView removeFromSuperview]; 
     } 
    } else { 
     if (toOrientation == UIInterfaceOrientationLandscapeLeft || 
      toOrientation == UIInterfaceOrientationLandscapeRight) { 
      [[self view] addSubview:landscapeView]; 
     }  
    } 
} 

हैं के रूप में आप की तरह है, तो आप भी कुछ इसी तरह के अंदर

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

की कोशिश कर सकते आप प्राप्त करना चाहते हैं: तो फिर आप इस का उपयोग करते हुए दृश्य जोड़ सकते हैं यहां तक ​​कि फैनसीयर, फिर आप मुख्य दृश्य को खाली छोड़ सकते हैं, UIView *portraitView और UIView *landscapeView दोनों बनाएं, फिर willRotateToInterfaceOrientation में वर्तमान दृश्य को हटाएं और didRotateToInterfaceOrientation में नया दृश्य जोड़ें।

सुरक्षा के लिए, आप यह भी सुनिश्चित करना चाहिए कि सही दृश्य शुरू में दिखाया गया है:

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation; 
    if (toOrientation == UIInterfaceOrientationPortrait || 
     toOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     [self.view addSubview:portraitView]; 
    } else { 
     [self.view addSubview:landscapeView]; 
    } 

} 

और भी

- (void)viewWillDisappear:(BOOL)animated 
{ 
    if ([landscapeView superview]) { 
     [landscapeView removeFromSuperview]; 
    } 
    if ([portraitView superview]) { 
     [portraitView removeFromSuperview]; 
    } 
} 
+0

इन विकल्पों में से कोई भी मेरे मामले में काम नहीं करेगा [और मैं वर्तमान में एक बक्षीस की पेशकश कर रहा हूं :-)]। मुझे नीचे एक विज्ञापन बैनर के साथ UIWebView मिला है; मैं लैंडस्केप दृश्य में बैनर को हटाना चाहता हूं। यदि मैं बैनर को हटाने के लिए समाधान # 1 का प्रयास करता हूं, तो UIWebView स्थान भरने के लिए आकार बदलता नहीं है। अगर मैं समाधान # 2 का प्रयास करता हूं, तो मैं अलग-अलग परिदृश्य/चित्र दृश्यों के बीच UIWebView साझा नहीं कर सकता। –

+0

ओह। यदि आपको बस इतना ही चाहिए, तो मैन्युअल रूप से वेबव्यू का आकार बदलें। – PengOne

0

एक विकल्प घुमाने पर एक crossfade संक्रमण के साथ एक मॉडल दृश्य पेश करने के लिए है , और जब इसे घुमाया जाता है तो उसे खारिज कर दिया जाता है।

10

सब एक UIWebView और एक विज्ञापन बैनर है मान लिया जाये कि आप है, तो आप सिर्फ मैन्युअल WebView आकार बदल सकते हैं जब परिदृश्य में:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation 
           duration:(NSTimeInterval)duration 
{ 
    if (toOrientation == UIInterfaceOrientationPortrait || 
     toOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
      [adView setHidden:NO]; 
     } 
    } else { 
     if (toOrientation == UIInterfaceOrientationLandscapeLeft || 
      toOrientation == UIInterfaceOrientationLandscapeRight) { 
      [adView setHidden:YES]; 
     }  
    } 
} 

फिर भी

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromOrientation 
           duration:(NSTimeInterval)duration 
{ 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation; 
    if (toOrientation == UIInterfaceOrientationPortrait || 
     toOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
      [webView setBounds:CGRectMake(0.0,0.0,320.0,436.0)]; 
     } 
    } else { 
     if (toOrientation == UIInterfaceOrientationLandscapeLeft || 
      toOrientation == UIInterfaceOrientationLandscapeRight) { 
      [webView setBounds:CGRectMake(0.0,0.0,480.0,320.0)]; 
     }  
    } 
} 

आयाम 44.0 ऊंचाई मान कर विज्ञापन बैनर और कोई एनवी बार (44.0) या स्टेटस बार (20.0) के लिए, इसलिए आपको अपने लेआउट के लिए संख्याओं को समायोजित करने की आवश्यकता हो सकती है।

+0

यह आश्चर्यजनक रूप से काम नहीं कर रहा है - या, बल्कि, यह काम कर रहा है, लेकिन एक बड़ी पकड़ है। यदि आप "willRotate" में इस तरह का आकार बदलते हैं, तो आईओएस रोटेशन के बाद आकार को दोबारा बदल देगा। तो जब पोर्ट्रेट पर जा रहे हैं, तो आपको 480x ~ 291 (100% x90%) पर वेब व्यू (वर्तमान में परिदृश्य) का आकार बदलना होगा; आईओएस इसे 320x436 में बदल देगा। परिदृश्य में जाने पर, आपको 320x480 का आकार बदलना होगा, जो आईओएस 480x320 में बदल जाएगा। (सिर विस्फोट) क्या वास्तव में कोई बेहतर तरीका नहीं है? –

+1

मैंने अपने पिछले जवाब दोनों इच्छाओं और विधियों में विघटित कर दिया। यह कार्यान्वयन में सुधार करना चाहिए। – PengOne

+0

'didRotateFromInterfaceOrientation' में आकार बदलने का लापता चाल था। मुझे इस कोड को 'viewWillAppear' में भी कॉल करना होगा, इसलिए यह @Panagiotis Korros का उत्तर नहीं दे सकता है, लेकिन यह मेरे बक्षीस के लायक है। –

0

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

तो, आप अनुप्रयोग संभालने जो 20 अंकों की ऊंचाई है एक शीर्षक पट्टी, प्रदर्शित करता है, यहाँ मैं क्या कर सकता है:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    CGFloat titleBarHeight = 20; 
    CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height; 
    if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){ 
     webView.frame = CGRectMake(0, 0, 320, 480 - titleBarHeight - navBarHeight - adView.frame.size.height); 
     adView.hidden = NO; 
    }else{ 
     webView.frame = CGRectMake(0, 0, 480, 320 - titleBarHeight - navBarHeight); 
     adView.hidden = YES; 
    } 
} 
+0

@PengOne पर मेरी टिप्पणी देखें। यह आश्चर्यजनक रूप से मुश्किल/सुरुचिपूर्ण है। क्या वास्तव में कोई बेहतर तरीका नहीं है? –

0

मैं अपने कोड में माता पिता को देखने के सीमा का लाभ उठाएं। नीचे दिए गए कोड को देखें कि एनीमेशन आपके लिए अच्छा काम करता है या नहीं।

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
    switch (toInterfaceOrientation) { 
     case UIInterfaceOrientationLandscapeLeft: 
     case UIInterfaceOrientationLandscapeRight: 
     { 
      webView.frame = self.view.bounds; 
     adView.hidden=YES; 
      break; 
     } 
    } 
} 


- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 

    switch (fromInterfaceOrientation) { 
     case UIInterfaceOrientationLandscapeLeft: 
     case UIInterfaceOrientationLandscapeRight: 
     { 
      webView.frame = originalFrame; 
      adView.hidden=NO; 
      break; 
     } 
    } 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    adView.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
    originalFrame = webView.frame; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 
संबंधित मुद्दे