我遇到了一个问题,当我按下按钮时,视图不会弹出。斯菲特

问题描述 投票:0回答:1

我遇到了一个问题,我不明白它没有向我显示弹出窗口的原因是什么。我有一个 xViewModel 类,我在其中调用该函数。该函数被定期调用,我通过断点检查它。

func showSliderPopup() {
    optionsBagBindables = DisposeBag()
    onStopLoader?()
    
    sliderPopup = SliderPopUp()
    
    sliderPopup.show()
}

SliderPopUp 是一个组件/视图,它是一个带有滑块的小方块,并且不会在其他视图前面显示为前视图/第一个视图。

这是逻辑所在组件的代码:

import UIKit
import RxSwift

enum SliderAction {
    case cancel
    case confirm
}

protocol RxSliderPopUpCellDelegate: CellDelegate {
    var onConfirm: PublishSubject<SliderAction> { get }
    var onCancel: PublishSubject<SliderAction> { get }
}

struct RxSliderPopUpBindables: RxSliderPopUpCellDelegate {
    var onConfirm: PublishSubject<SliderAction>
    var onCancel: PublishSubject<SliderAction>

    init() {
        onConfirm = PublishSubject()
        onCancel = PublishSubject()
    }
}

protocol SliderDelegate: AnyObject {
    func action(view: SliderPopUp, action: SliderAction)
}

class SliderPopUp: UIView {
    private var nibName = "SliderPopUp"
        
    @IBOutlet weak var viewBackground: UIView!
    @IBOutlet weak var popupView: UIView!
    @IBOutlet weak var lblTitle: UILabel!
    @IBOutlet weak var numberOfInstalments: UILabel!
    @IBOutlet weak var slider: UISlider!
    @IBOutlet weak var stackView: UIStackView!
    @IBOutlet weak var leftBtn: UIButton!
    @IBOutlet weak var rightBtn: DBButton!
    
    private var popupTitle: String?
    private var desc: String?
    private var moveY: CGFloat?
    private var vM: RxSliderPopUpBindables?
    private var shouldHidePopup: Bool = true
    private var disposeBag = DisposeBag()

    override func awakeFromNib() {
        super.awakeFromNib()
        self.cornerRadius = 6

    }
    
    convenience init(title: String, description: String, viewmodel: RxSliderPopUpBindables?, shouldHidePopup: Bool = true) {
        let overalFrame = CGRect(x: 0, y: 0, width: Constants.Device.width, height: Constants.Device.height)
        self.init(frame: overalFrame)
        self.popupTitle = title
        self.desc = description
        self.shouldHidePopup = shouldHidePopup
        self.vM = viewmodel
        disposeBag = DisposeBag()
        
        commonInit()
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
    }
    
    func commonInit() {
        Bundle.main.loadNibNamed(nibName, owner: self, options: nil)
        viewBackground.frame = self.bounds
        viewBackground.autoresizingMask = \[.flexibleWidth, .flexibleHeight\]
        
        lblTitle.text = self.popupTitle
        lblTitle.font = FontHelper.popupTitle.font()
        lblTitle.addNegativeLineSpace()
        lblTitle.isCopyingEnabled = true
        
        lblTitle.text = LnKeys.numberOfInstalmentsPopUp.localized
        lblTitle.font = FontHelper.popupTitle.font()
        lblTitle.textAlignment = .left
        lblTitle.addNegativeLineSpace()
        
        leftBtn.titleLabel?.font = FontHelper.popupBtns.font()
        leftBtn.setTitleColor(ColorHelper.popupCancelBtn.color(), for: .normal)
        leftBtn.addText(LnKeys.popupBtnCancel.localized, spacing: 2)
        
        rightBtn.titleLabel?.font = FontHelper.popupBtns.font()
        rightBtn.addText(LnKeys.popupConfirm.localized, spacing: 2)
        rightBtn.isEnabled = false
        rightBtn.isImagePresent = false
        
        viewBackground.backgroundColor = UIColor.black.withAlphaComponent(0.6)
        addSubview(viewBackground)
    }
    
    // MARK: - Public funcs
    func show() {
        UIApplication.shared.windows.first(where: \.isKeyWindow)?.addSubview(self)
    }

    func hide() {
        self.removeFromSuperview()
    }
    
    @IBAction func btnCancel(_ sender: Any) {
        hide()
    }
    
    @IBAction func btnConfirm(_ sender: Any) {
//        if let vM = self.vM {
//            vM.onConfirm.asObserver().onNext()
//        }
        hide()
    }
}
swift rx-swift
1个回答
0
投票

检查委托设置是否正确 并验证 sliderPopUp 没有隐藏在其他视图后面

© www.soinside.com 2019 - 2024. All rights reserved.