欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS實(shí)現(xiàn)Pad上菜單彈出界面

 更新時(shí)間:2017年06月19日 13:47:41   作者:那一抹風(fēng)情  
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)Pad上菜單彈出界面的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

前言:

此種方式實(shí)現(xiàn)只適用于pad開發(fā),在iPhone上是無效的。

實(shí)現(xiàn):

比如我在界面上有一個(gè)按鈕,點(diǎn)擊按鈕,在按鈕旁邊彈出一個(gè)Pop框。

1、按鈕點(diǎn)擊事件

btn.addTarget(self, action: #selector(self.popShow), for: .touchUpInside)

2、事件處理

 /// 彈框選擇條件
 ///
 /// - Parameter sender: <#sender description#>
 func popShow(sender:UIButton) {
  let popVC = ExerciseLibPopViewController()
  popVC.modalPresentationStyle = .popover
  popVC.preferredContentSize = CGSize(width: 111, height: 2*44.0)
  popVC.popoverPresentationController?.sourceView = sender
  popVC.popoverPresentationController?.sourceRect = sender.bounds
  popVC.popoverPresentationController?.delegate = self
  self.present(popVC, animated: true, completion: nil)

 }

其中,popover類有一個(gè)代理:

extension xxxViewController : UIPopoverPresentationControllerDelegate {
 func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
  print("popoverPresentationControllerShouldDismissPopover")
  // 處理你要做的

  return true
 }
}


類似效果如下:

 

最后小Tips:

1、如果這里需要把上圖的小箭頭背景色改成其他顏色(和里面顏色一致)

加上這句即可:

popVC.popoverPresentationController?.backgroundColor = UIColor.white

2、如果想改變彈出框位置,修改這句即可:

// 將bounds改成CGRect(x,y,w,h)自己構(gòu)造參數(shù)
popVC.popoverPresentationController?.sourceRect = sender.bounds

 以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論