我有一个UIAlertController,我正在尝试向它添加一个箭头并将sourceView更改为self.button,因此它不会出现在底部。
这是我到目前为止所得到的:
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仍然出现在底部。我做错了什么?
答案 0 :(得分:0)
popoverPresentationController
(以及它的设置)旨在由UIViewController
presentationStyle
UIModalPresentationPopover
UIAlertController
使用。
虽然UIViewController
是UIModalPresentationCustom
的子类,但它很特殊并使用presentationStyle
作为其presentationStyle
。设置新UIAlertController
的尝试将被忽略。
我不认为你要做的是{{1}}的预期用途。你最好的办法就是让你自己的视图控制器达到这个目的。