关于NewPopMenu的bug解决

NewPopMenu会在第二次点击自动缩小且无法改变,代码如下:

    lazy var scrollViewController : PopMenuViewController = {

        var actions : [PopMenuDefaultAction] = []

        (0...4).map{ index in
            var action = PopMenuDefaultAction(title: BallNames[index],image: UIImage(named: "\(ButtonImages[index])"))
            action.imageRenderingMode = .alwaysOriginal

            actions.append(action)

        }

        let vc = PopMenuViewController(sourceView: menuButton,actions: actions)


        vc.appearance.popMenuColor.backgroundColor = .solid(fill: .init(red: 0.431372549, green: 0.6470588235, blue: 0.4509803922, alpha: 1))

//        vc.appearance.popMenuActionHeight = 65

        vc.appearance.popMenuActionCountForScrollable = 3



        return vc
    }()

解决方法:

不用懒加载,而是每次用的时候再实例化一次,懒加载从头到尾只实例化了一次而已。

代码如下:

    @objc func popMenu(){
        
        //MARK: 要重新的实例化 不然就会导致第二次点击的时候 缩小
                let vc = PopMenuViewController(sourceView: menuButton,actions: actions)
        
        
                vc.appearance.popMenuColor.backgroundColor = .solid(fill: .init(red: 0.431372549, green: 0.6470588235, blue: 0.4509803922, alpha: 1))
        
                vc.appearance.popMenuActionHeight = 65
        
                vc.appearance.popMenuActionCountForScrollable = 3
        vc.contentFrame = CGRect(x: 220, y: 605, width: 120.65, height: 175)
        vc.delegate = self
        self.present(vc, animated: true,completion: nil)
        
    }

你可能感兴趣的:(swift,bug,swift,ios)