Изменить стрелку всплывающего окна листа действий в iOS8

я использую UIAlertController . Но на iPad с iOS 8 actionSheet отображается со стрелкой всплывающего окна. Есть идеи, как спрятать эту стрелку?

Вот мой код:

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];

person TienLe    schedule 17.09.2014    source источник
comment
stackoverflow.com/questions/4755786/   -  person Alfa    schedule 17.09.2014
comment
используйте [alertControllerActionSheet.popoverPresentationController setPermittedArrowDirections:0];   -  person Jageen    schedule 17.09.2014


Ответы (4)


Решение:
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];

Вывод

введите здесь описание изображения

person Jageen    schedule 17.09.2014
comment
rect.orign.x = ... и .y == ... не требуются. - person tuoxie007; 15.11.2014

Ответ Джагина в Swift:

popoverController.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
person mark    schedule 29.08.2015

Выбранный ответ не центрирует оповещение, если у вас есть панель навигации/состояния. Чтобы точно центрировать ваш контроллер предупреждений:

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)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    // Check if your alert controller is still being presented
    if (alertController.presentingViewController) {
        alertController.popoverPresentationController.sourceRect = [self sourceRectForCenteredAlertController];
    }
}

Или, если вы не хотите использовать события поворота, вы можете использовать метод делегата popoverPresentationController для изменения положения всплывающего окна:

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

Вы находитесь на неправильном пути, используя 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];
person crosscode    schedule 17.09.2014