日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

02-Popover代码实现

發(fā)布時(shí)間:2024/9/30 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 02-Popover代码实现 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Popover代碼實(shí)現(xiàn)

  • 這一小節(jié)我們主要通過(guò)代碼來(lái)實(shí)現(xiàn)popover跳轉(zhuǎn)來(lái)學(xué)習(xí)popover更多的一些常用屬性

  • 效果預(yù)覽

  • ViewController.swift
import UIKitclass ViewController: UIViewController {@IBOutlet weak var testButton: UIButton!override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.}@IBAction func textButtonClick(sender: AnyObject) {print("你點(diǎn)擊到人家啦~~~")}//UIBarButtonItem@IBAction func popoverButtonClick(sender: AnyObject) {//1.創(chuàng)建popover的目標(biāo)控制器let desVC = UIViewController()desVC.view.backgroundColor = UIColor.purpleColor()//2.設(shè)置控制器跳轉(zhuǎn)樣式desVC.modalPresentationStyle = UIModalPresentationStyle.Popover//3.獲取目標(biāo)控制器的popover對(duì)象let popoverVC = desVC.popoverPresentationControllerpopoverVC?.backgroundColor = UIColor.redColor()//4.設(shè)置箭頭方向popoverVC?.permittedArrowDirections = UIPopoverArrowDirection.Unknown//4.跳轉(zhuǎn)//非UIBarBUttonItemif let btn = sender as? UIButton{//設(shè)置來(lái)源視圖popoverVC?.sourceView = btn//設(shè)置參考點(diǎn)popoverVC?.sourceRect = btn.bounds//忽略外部點(diǎn)擊 默認(rèn)為false 如果設(shè)置為true 表示 點(diǎn)擊外部popover不會(huì)消失 需要手動(dòng)添加按鈕消失 如果為false 表示點(diǎn)擊外部視圖 popover會(huì)消失desVC.modalInPopover = false//設(shè)置點(diǎn)擊穿透視圖popoverVC?.passthroughViews = [testButton]}else if let item = sender as? UIBarButtonItem //UIBarBUttonItem{//UIBarButtonItem 設(shè)置參考點(diǎn)無(wú)效 設(shè)置來(lái)源視圖是通過(guò)barButtonItem屬性popoverVC?.barButtonItem = item}//model跳轉(zhuǎn)presentViewController(desVC, animated: true) { () -> Void in}}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}}
  • 總結(jié)
  • popover屬性

    • permittedArrowDirections:設(shè)置箭頭方向 系統(tǒng)默認(rèn)為UnKnown
    • sourceView:來(lái)源視圖(只針對(duì)非UIBarButtonItem)
      • 原因:UIBarButtonItem不是UIView的子類(lèi)
    • barButtonItem:來(lái)源視圖(只針對(duì)UIBarButtonItem)
    • sourceRect:目標(biāo)參考點(diǎn)(只針對(duì)非UIBarButtonItem,UIBarButtonItem設(shè)置無(wú)效)
    • passthroughViews:設(shè)置穿透視圖(可以點(diǎn)擊該視圖交互事件)
  • UIViewController屬性

    • preferredContentSize:設(shè)置popover的大小
    • modalInPopover:是否忽略外部點(diǎn)擊(默認(rèn)為false 如果設(shè)置為true 表示 點(diǎn)擊外部popover不會(huì)消失 需要手動(dòng)添加按鈕消失 如果為false 表示點(diǎn)擊外部視圖 popover會(huì)消失)

總結(jié)

以上是生活随笔為你收集整理的02-Popover代码实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。