zoukankan      html  css  js  c++  java
  • iOS 适用于Pad上的菜单弹出界面-最简单的一种实现记录

    前言:

    此种方式实现只适用于pad开发,在iPhone上是无效的。

    实现:

    比如我在界面上有一个按钮,点击按钮,在按钮旁边弹出一个Pop框。

    1、按钮点击事件

    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( 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类有一个代理:

    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)自己构造参数
    popVC.popoverPresentationController?.sourceRect = sender.bounds
  • 相关阅读:
    namespaces in C++
    cout如何刷新缓冲区
    Journey CodeForces 1336F[data structures divide and conquer graphs trees]
    using ll=long long;
    Kaavi and Magic Spell CodeForces 1337E【dp strings】
    摸个🐟
    gcc的几个有用的处理二进制位的内置函数
    Yui and Mahjong Set CodeForces 1337F 【interactive】交互式题
    C++ auto 的使用
    2005年微软十大安全漏洞 java程序员
  • 原文地址:https://www.cnblogs.com/yajunLi/p/7048327.html
Copyright © 2011-2022 走看看