20

में एक्शन शीट पॉपओवर तीर बदलें मैं UIAlertController का उपयोग कर रहा हूं। लेकिन आईओएस 8 के साथ आईपैड पर, एक्शनशीट पॉपओवर तीर के साथ दिखाता है। उस तीर को छिपाने के लिए कोई विचार?आईओएस 8

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"this is alert controller" message:@"yeah" preferredStyle:UIAlertControllerStyleActionSheet]; 

      UIAlertAction *cancelAction = [UIAlertAction 
              actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action") 
              style:UIAlertActionStyleCancel 
              handler:^(UIAlertAction *action) 
              { 
               NSLog(@"Cancel action"); 
              }]; 

      UIAlertAction *okAction = [UIAlertAction 
             actionWithTitle:NSLocalizedString(@"OK", @"OK action") 
             style:UIAlertActionStyleDefault 
             handler:^(UIAlertAction *action) 
             { 
              NSLog(@"OK action"); 
             }]; 

      UIAlertAction *deleteAction = [UIAlertAction 
              actionWithTitle:NSLocalizedString(@"Delete", @"Delete action") 
              style:UIAlertActionStyleDestructive 
              handler:^(UIAlertAction *action) { 
               NSLog(@"Delete action"); 
              }]; 

      [alertController addAction:cancelAction]; 
      [alertController addAction:okAction]; 
      [alertController addAction:deleteAction]; 

      UIPopoverPresentationController *popover = alertController.popoverPresentationController; 
      if (popover) { 
       popover.sourceView = self.view; 
       popover.sourceRect = self.view.bounds; 
       popover.permittedArrowDirections = UIPopoverArrowDirectionUnknown; 
      } 
      [self presentViewController:alertController animated:YES completion:nil]; 
+0

http://stackoverflow.com/questions/:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { // Check if your alert controller is still being presented if (alertController.presentingViewController) { alertController.popoverPresentationController.sourceRect = [self sourceRectForCenteredAlertController]; } } 

या, आप रोटेशन घटनाओं का उपयोग नहीं करना चाहते हैं तो आपको popoverPresentationController प्रतिनिधि विधि पॉपओवर स्थान बदलने के लिए उपयोग कर सकते हैं 4755786/कैसे-से-निकालें-आईपैड-पॉपओवर-तीर-और-इसकी-फ्रेम-सीमा – Alfa

+0

का उपयोग करें [चेतावनी नियंत्रकएक्शनशीट.popoverPresentationController setPermittedArrowDirections: 0]; – Jageen

उत्तर

37

समाधान:
use below line for remove arrow from action sheet

[yourAlertController.popoverPresentationController setPermittedArrowDirections:0]; 


नमूना

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Test Action Sheet" message:@"Message" preferredStyle:UIAlertControllerStyleActionSheet]; 

    UIAlertAction *cancelAction = [UIAlertAction 
            actionWithTitle:@"Cancel" 
            style:UIAlertActionStyleDestructive 
            handler:^(UIAlertAction *action) 
            { 
             NSLog(@"Cancel action"); 
            }]; 

    UIAlertAction *okAction = [UIAlertAction 
           actionWithTitle:@"Ok" 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction *action) 
           { 
            NSLog(@"OK action"); 
           }]; 
    UIAlertAction *otherAction = [UIAlertAction 
           actionWithTitle:@"Other" 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction *action) 
           { 
            NSLog(@"Otheraction"); 
           }]; 

    [alertController addAction:okAction]; 
    [alertController addAction:otherAction]; 
    [alertController addAction:cancelAction]; 


    // Remove arrow from action sheet. 
    [alertController.popoverPresentationController setPermittedArrowDirections:0]; 

    //For set action sheet to middle of view. 
    alertController.popoverPresentationController.sourceView = self.view; 
    alertController.popoverPresentationController.sourceRect = self.view.bounds; 

    [self presentViewController:alertController animated:YES completion:nil]; 



enter image description here

+2

rect.orign.x = ... और .y == ... आवश्यक नहीं हैं। – tuoxie007

-1

आप UIPopoverPresentationController का उपयोग कर एक चेतावनी प्रदर्शित करने के लिए गलत ट्रैक पर कर रहे हैं:

यहाँ मेरी कोड है। आप सिर्फ इतना है कि कोड की कतरना की जरूरत नहीं है ...

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"this is alert controller" message:@"yeah" preferredStyle:UIAlertControllerStyleActionSheet]; 

     UIAlertAction *cancelAction = [UIAlertAction 
             actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action") 
             style:UIAlertActionStyleCancel 
             handler:^(UIAlertAction *action) 
             { 
              NSLog(@"Cancel action"); 
             }]; 

     UIAlertAction *okAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"OK", @"OK action") 
            style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction *action) 
            { 
             NSLog(@"OK action"); 
            }]; 

     UIAlertAction *deleteAction = [UIAlertAction 
             actionWithTitle:NSLocalizedString(@"Delete", @"Delete action") 
             style:UIAlertActionStyleDestructive 
             handler:^(UIAlertAction *action) { 
              NSLog(@"Delete action"); 
             }]; 

     [alertController addAction:cancelAction]; 
     [alertController addAction:okAction]; 
     [alertController addAction:deleteAction]; 

     [self presentViewController:alertController animated:YES completion:nil]; 
+2

यह आईपैड पर काम नहीं करेगा। – TienLe

6

Jageen के जवाब आउटपुट, स्विफ्ट में:

popoverController.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0) 
6

चयनित जवाब चेतावनी केंद्र नहीं पड़ता कि आप एक एनएवी/स्थिति पट्टी की है।

alertController.popoverPresentationController.sourceRect = [self sourceRectForCenteredAlertController]; 
alertController.popoverPresentationController.sourceView = self.view; 
alertController.popoverPresentationController.permittedArrowDirections = 0; 
सुविधा विधि के साथ

:

- (CGRect)sourceRectForCenteredAlertController 
{ 
    CGRect sourceRect = CGRectZero; 
    sourceRect.origin.x = CGRectGetMidX(self.view.bounds)-self.view.frame.origin.x/2.0; 
    sourceRect.origin.y = CGRectGetMidY(self.view.bounds)-self.view.frame.origin.y/2.0; 
    return sourceRect; 
} 

इसके अलावा, चेतावनी नियंत्रक केंद्रित रहने नहीं करता है तो दृश्य घुमाया जाता है वास्तव में आपकी सूचना के नियंत्रक को केंद्रित करने के। केंद्रित चेतावनी नियंत्रक को रखने के लिए आपको रोटेशन के बाद SourceRect को अपडेट करने की आवश्यकता है। उदाहरण के लिए:

- (void)popoverPresentationController:(UIPopoverPresentationController *)popoverPresentationController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing _Nonnull *)view 
{ 
    // Re-center with new rect 
}