2010-06-09 15 views
9

मेरे ऐप में मेरे पास 3 यूआईपीओपीओवर हैं। वे तब दिखाई देते हैं जब उपयोगकर्ता टूलबार में बटन टैप करता है। यदि पॉपओवर पहले ही खोला गया है (जैसे -विल एनीमोटोटेशन टॉइंटरफेसऑरिएंटेशन :) जैसे उपयोगकर्ता को आईपैड घुमाता है तो पॉपओवर को सही जगह पर दिखाना होगा।यूआईपीओपीओवर और अभिविन्यास परिवर्तन

मैं यह कैसे कर सकता हूं?

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

उत्तर

6

एकमात्र समाधान मैं अब तक मिल गया है बस जब डिवाइस घुमाया जाता है पॉपओवर बंद हो रहा है/

+0

दुख की बात है, मैं कुछ भी नहीं मेरे विचार नियंत्रक के willRotate विधि है, जहां मैं सामान्य रूप से पॉपओवर खारिज होता गति प्रदान करने के मिल सकता है। मुझे लगता था कि इससे कोई फर्क नहीं पड़ता कि क्या होगा। –

+0

मैं इस समाधान के बारे में भी सोचता हूं, मैं इसे नहीं कर सकता। :( –

3

आप बस अपने पॉपओवर पेश करने के लिए presentPopoverFromBarButtonItem विधि का उपयोग करें तो पॉपओवर स्वचालित रूप से सही स्थिति के लिए के लिए आ जाएगा डिवाइस घुमाए जाने पर नई बटन स्थिति।

2

क्या आप presentPopoverFromBarButtonItem या FromRect को कॉल कर रहे हैं? क्या आप बारबटन इटिम में घूमने पर कोई बदलाव कर रहे हैं?

ऐप्पल के दस्तावेज़ विशेष रूप से बताते हैं कि आपको FromRect के लिए रोटेशन पर स्थिति प्रबंधित करने की आवश्यकता है या यदि आप बार बटन आइटम को संशोधित करते हैं। http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPopoverController_class/Reference/Reference.html

4

में चौथा पैराग्राफ देखें मेरी परियोजनाओं में से एक कोड कोड है। असल में, यदि पॉपओवर दिखा रहा है, तो आप didRotateFromInterfaceOrientation: विधि में पॉपओवर को फिर से प्रस्तुत करते हैं, जो के बाद उपयोगकर्ता नियंत्रक रोटेशन के बाद व्यू कंट्रोलर पर भेजा जाता है। (willRotate... और willAnimateRotation... तरीकों, से पहले रोटेशन हुआ है कहा जाता है तो यह presentPopover... विधि कॉल के लिए गलत जगह है।)

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    // if the popover is showing, adjust its position after the re-orientation by presenting it again: 
    if (self.myPopoverController != nil) // if the popover is showing (replace with your own test if you wish) 
    { 
    [self.myPopoverController presentPopoverFromRect:attachmentRect 
               inView:myView 
          permittedArrowDirections:UIPopoverArrowDirectionUp 
              animated:YES]; 
    }  
} 

ऊपर में, self.myPopoverController मेरे विचार नियंत्रक जहां की संपत्ति है जब इसे बनाया जाता है तो मैं पॉपओवर का संदर्भ संग्रहीत करता हूं। जब मैं सामान्य परिस्थितियों में पॉपओवर को खारिज कर देता हूं और छोड़ देता हूं, तो मैं इस संपत्ति को nil पर सेट करने का ख्याल रखता हूं, इसलिए मैं यह तय करने के लिए 'गैर-nil' नेस के लिए जांच सकता हूं कि पॉपओवर दिखाया जा रहा है या नहीं।

नोट, हालांकि, आपको रोटेशन होने से पहले पॉपओवर को खारिज करने की आवश्यकता नहीं है। बस एक ही पॉपओवर फिर से प्रस्तुत करें। (यह जहां पॉपओवर के लिए एक संदर्भ में रखते हुए काम में आता है।)

अपने मामले, जहां पॉपओवर एक उपकरण पट्टी बटन से उत्पन्न दौरान, आप निम्नलिखित की तरह कुछ का प्रयोग करेंगे:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    // if the popover is showing, adjust its position after the re-orientation by presenting it again: 
    if (self.myPopoverController != nil) // if the popover is showing (replace with your own test if you wish) 
    { 
    [self.myPopoverController presentPopoverFromBarButtonItem:barButtonItem 
            permittedArrowDirections:UIPopoverArrowDirectionAny 
                animated:YES]; 
    }  
} 
2

मैं मैं इस मुद्दे को दो बार चलाता हूं। मैं आम तौर पर सिर्फ एक विधि पॉपओवर इस तरह केंद्रित को दिखाने के लिए:

- (void) showPopoverForSize:(CGSize) size center:(CGPoint) center { 
    CGFloat width = size.width; 
    CGFloat height = size.height; 
    CGFloat x = center.x - width/2; 
    CGFloat y = center.y - height/2; 
    CGRect frame = CGRectMake(x, y, width, height); 
    popover.popoverContentSize = frame.size; 

    [popover presentPopoverFromRect:frame inView:self.view permittedArrowDirections:0 animated:YES]; 
} 

फिर didRotate पर मुझे क्या करना:

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    if (popover.isPopoverVisible) 
     [self showPopoverForSize:popover.popoverContentSize center:self.view.center]; 
} 

यह किसी भी उन्मुखीकरण के लिए केंद्र में पॉपओवर डाल देंगे।

10

आईओएस 7 में।0 और बाद में, यह निम्नलिखित विधि उपलब्ध लागू करने से किया जा सकता है UIPopoverControllerDelegate में:

(void)popoverController:(UIPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView **)view

R आर कि presentPopoverFromRect विधि का उपयोग कर प्रस्तुत किए गए के लिए, पॉपओवर नियंत्रक इस विधि कॉल इंटरफ़ेस उन्मुखीकरण बदल जाता है।

+0

यह आईओएस 7 के बाद ऐसा करने का सबसे अच्छा तरीका है। – logancautrell

+0

'सीजीआरईटी फ्रेम = self.myView.frame; * rect = frame;' – logancautrell

+0

यह 'drawRect' के साथ एक और बग भी तय किया गया है जिसे दोबारा नहीं बुलाया जा रहा है मेरे पॉपओवर में देखें। ग्रेट उत्तर, स्वीकार्य होना चाहिए !!! –

1

उन्मुखीकरण के परिवर्तन की शुरुआत में पॉपओवर खारिज, और अभिविन्यास के परिवर्तन इसे फिर से पूर्ण होने के बाद और यह स्क्रीन पर अपनी स्थिति को वर्तमान परिवर्तन:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
      [_popover dismissPopoverAnimated:YES]; 
     } 
    } 

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
    { 
     if (_popover) { 
      [_popover presentPopoverFromRect:frameRect 
                 inView:self.view 
            permittedArrowDirections:UIPopoverArrowDirectionUp 
                animated:YES]; 
     }  
    } 
+0

कृपया कोड पेस्ट करने के बजाए अधिक जानकारी जोड़ें। – kinshuk4

0

प्रदर्शन पॉपओवर समारोह:

func presentPopover() { 
    self.popoverFlag = true 
    //Presenting PopOver code goes here 
    // ... 
} 

बदलते रुख पर प्रस्तुत पॉपओवर खारिज:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { 

     if self.isKindOfClass(ViewController) && self.popoverFlag{ 
      guard self.presentedViewController != nil else { return } 
      dispatch_async(dispatch_get_main_queue()) { 
       self.presentedViewController!.dismissViewControllerAnimated(true, completion: nil) 
      } 
     } 
    } 

पेश फिर पॉपओवर:

func popoverPresentationController(popoverPresentationController: UIPopoverPresentationController, willRepositionPopoverToRect rect: UnsafeMutablePointer<CGRect>, inView view: AutoreleasingUnsafeMutablePointer<UIView?>) { 
    self.presentPopover() 
} 
संबंधित मुद्दे