簡體   English   中英

彈出框更改位置起點(原始位置)iOS9

[英]popover change position starting point (origin location) iOS9

我想在其他位置展示我的彈出窗口。 默認情況下,它從用戶選擇按鈕的地方開始。 我正在使用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?
custom.popoverPresentationController?.sourceRect = CGRectMake(100,100,100,100)

CGRectMake(x.origin,y.origin,width,height)

新解決方案iOS 8+

// Create Controller

var popoverContent = CustomPop()

// Get NavController
var nav = UINavigationController(rootViewController: popoverContent)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover

// Get PopoverPresentationController 
var popover = nav.popoverPresentationController as UIPopoverPresentationController
popover.sourceView = self.view
popover.sourceRect = CGRectMake(100,100,0,0)

// Show Popover
self.presentViewController(nav, animated: true, completion: nil) 

使用不推薦使用的UIPopoverController

// Create Controller
UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];

// Set Point
[pc presentPopoverFromRect:CGRectMake(0, 0, 100, 100)
                    inView:self.view 
                    permittedArrowDirections:UIPopoverArrowDirectionAny 
                    animated:YES];

swift 3.1中嘗試一下:

MZFormSheetPresentationController.appearance().movementActionWhenKeyboardAppears = .alwaysAboveKeyboard

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM