2015-08-08 2 views
0

Я пытаюсь отобразить UIAlertController с помощью некоторых кнопок действий. Он отлично работает на iPhone, потому что он появляется со дна устройства. У меня проблема с ipad, UIAlertController не центрируется должным образом. Он показывает немного вправо. Я могу вычесть из координаты x, вычитая say 150f. Есть ли способ получить это в центре?UIAlertController - iOS 8 - iPad - не правильно настроен

UIAlertController * view= [UIAlertController 
          alertControllerWithTitle:@"My Title" 
          message:@"Select your Choice" 
          preferredStyle:UIAlertControllerStyleActionSheet]; 

UIAlertAction* ok = [UIAlertAction 
        actionWithTitle:@"OK" 
        style:UIAlertActionStyleDefault 
        handler:^(UIAlertAction * action) 
        { 
         //Do some thing here 
         [view dismissViewControllerAnimated:YES completion:nil]; 

        }]; 
UIAlertAction* cancel = [UIAlertAction 
         actionWithTitle:@"Cancel" 
         style:UIAlertActionStyleDefault 
         handler:^(UIAlertAction * action) 
         { 
          [view dismissViewControllerAnimated:YES completion:nil]; 

         }]; 


[view addAction:ok]; 
[view addAction:cancel]; 



view.popoverPresentationController.sourceView = self.view; 
view.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0, 0.0, 0.0); 
[self presentViewController: view animated:YES completion:nil]; 
+1

Что такое 'self.view.frame' относительно' [UIScreen mainScreen] .bounds'? Является ли он идеально сосредоточенным? – Stuart

ответ

1

Если у вас есть простые действия, то лучше использовать Alertstyle, он центрируется автоматически или, если вы настаиваете, чтобы использовать Actionsheet стиль, попробуйте установить popoverPresentationController.permittedArrowDirections = 0 это работает хорошо с фиксированной ориентацией, но терпит неудачу, если вы повернете в IPad.

// Alert 
- (void) showAlert 
{ 
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"TEst" message:@"test Message" preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

    }]; 

    [alertController addAction:cancelAction]; 


    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil]; 
} 
Смежные вопросы