1

我正在使用一个名为 JTAppleCalendar 的 cocoapods。

我遇到了一种情况,我只能用两根手指同时触摸屏幕来选择日期。我必须在 Xcode 中取消选中“多点触控”,并且还尝试以编程方式禁用多点触控,但问题仍然存在。如果有人可以帮助我,我将不胜感激。

这是代码:

override func viewDidLoad() {
        super.viewDidLoad()
        setupCalendarView()
        self.calendarView.isMultipleTouchEnabled = false 
     }
 func setupCalendarView(){
        calendarView.minimumLineSpacing = 0
        calendarView.minimumInteritemSpacing = 0 
        calendarView.visibleDates{ (visibleDates) in
            self.setupViewofCalendar(from: visibleDates)
        }
    }

func setupViewofCalendar(from visibleDates: DateSegmentInfo){
        let date = visibleDates.monthDates.first!.date

        self.formatter.dateFormat = "yyyy"
        self.year.text =  self.formatter.string(from:date)

        self.formatter.dateFormat = "MMMM"
        self.month.text =  self.formatter.string(from:date)
    }
func handleCellTextColor(view: JTAppleCell?, cellState: CellState) {
        guard let validCell = view as? CalendarCustomCell else { return }
        if cellState.isSelected {
            validCell.dateLabel.textColor = selectedMonthColor
            validCell.selectedView.isHidden = false
        } else {
            if cellState.dateBelongsTo == .thisMonth{
                validCell.dateLabel.textColor = UIColor.black
            }
            else{
                validCell.dateLabel.textColor = outsideMonthColor
            }
            validCell.selectedView.isHidden = false

        }
    }
 func handleCellSeleted(view: JTAppleCell?, cellState: CellState) {
        guard let validCell = view as? CalendarCustomCell else { return }

        if validCell.isSelected {
            validCell.selectedView.isHidden = false
        } else {
            validCell.selectedView.isHidden = true
        }
    }

extension calendarViewController: JTAppleCalendarViewDataSource{
    func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
        formatter.dateFormat = "yyyy MM dd"
        formatter.timeZone = Calendar.current.timeZone
        formatter.locale = Calendar.current.locale

        let todayDate = Date()
        let endDate = Calendar.current.date(byAdding: .month, value: 12, to: Date())

        let parameters = ConfigurationParameters(startDate: todayDate, endDate: endDate!)

        return parameters
    }
}

extension calendarViewController: JTAppleCalendarViewDelegate {
    //display cell
    func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CalendarCustomCell

        cell.dateLabel.text = cellState.text

        handleCellTextColor(view: cell, cellState: cellState)
        handleCellSeleted(view: cell, cellState: cellState)

        return cell
    }

    func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {

        handleCellTextColor(view: cell, cellState: cellState)
        handleCellSeleted(view: cell, cellState: cellState)
    }

    func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleCell?, cellState: CellState) {

        handleCellTextColor(view: cell, cellState: cellState)
        handleCellSeleted(view: cell, cellState: cellState)
    }

    func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {
       setupViewofCalendar(from: visibleDates)
    }
}
4

0 回答 0