我想在不同的位置展示我的popover。默认情况下,它从用户选择按钮开始。我使用的是UIVIewController而不是UIPopoverController,因为在iOS9中不推荐使用UIPopoverController
class CustomPop: UIViewController, UIPopoverPresentationControllerDelegate {
init() {
super.init(nibName: nil, bundle: nil)
self.modalPresentationStyle = UIModalPresentationStyle.Popover;
self.popoverPresentationController?.delegate = self;
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle{
return .None
}
}
//for example something like this but I need it for a popover:
custom = CustomPop()
custom.frame.origin.y = self.view.height - 100
// is there a way to use CGRectMake for the popover to accomplish this?
答案 0 :(得分:1)
custom.popoverPresentationController?.sourceRect = CGRectMake(100,100,100,100)
CGRectMake(x.origin,y.origin,width,height)
答案 1 :(得分:0)
新解决方案iOS 8 +
// Create Controller
UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];
// Set Point
[pc presentPopoverFromRect:CGRectMake(0, 0, 100, 100)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
使用UIPopoverController 已弃用
{{1}}
答案 2 :(得分:-1)
在 swift 3.1 :
中试试MZFormSheetPresentationController.appearance().movementActionWhenKeyboardAppears = .alwaysAboveKeyboard