2016-08-16 6 views
0

У меня есть UIAlertController, и я пытаюсь добавить к нему стрелку и изменить sourceView на self.button, чтобы он не отображался внизу.Swift Добавить стрелку и sourceView в UIAlertController

Это то, что я до сих пор:

let dropdown = UIAlertController(title: "Select Room", message: nil, preferredStyle: .ActionSheet) 

     let kitchen = UIAlertAction(title: "Kitchen", style: .Default) { (action) in 
     } 
     dropdown.addAction(kitchen) 

     let livingRoom = UIAlertAction(title: "Living Room", style: .Default) { (action) in 
     } 
     dropdown.addAction(livingRoom) 

     let bedroom = UIAlertAction(title: "Bedroom", style: .Default) { (action) in 
     } 
     dropdown.addAction(bedroom) 

     let bathroom = UIAlertAction(title: "Bathroom", style: .Default) { (action) in 
     } 
     dropdown.addAction(bathroom) 

     let cancel = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in 
     } 
     dropdown.addAction(cancel) 

     dropdown.modalPresentationStyle = .Popover 

     dropdown.popoverPresentationController?.sourceRect = self.dropdownButton.frame 
     dropdown.popoverPresentationController?.sourceView = self.dropdownButton 
     dropdown.popoverPresentationController?.permittedArrowDirections = .Up 

     self.presentViewController(dropdown, animated: true, completion: nil) 

Но стрелка не появляется, и UIAlertController все еще появляется в нижней части. Что я делаю не так?

+1

Вы получаете стрелку только на iPad. На iPhone это всегда полный экран без стрелки. – rmaddy

ответ

0

popoverPresentationController (и его настройки) предназначены для использования UIViewController, который presentationStyle является UIModalPresentationPopover.

Хотя UIAlertController подкласс UIViewController, он является особенным и использует UIModalPresentationCustom, как это presentationStyle. Попытки установить новый presentationStyle игнорируются.

Я не думаю, что вы пытаетесь сделать это по назначению для UIAlertController. Лучше всего сделать свой собственный контроллер просмотра для достижения этой цели.

Смежные вопросы