Задержка табличного представления (даже после удаления распознавателей жестов) - PullRequest
0 голосов
/ 13 марта 2019

В настоящее время у меня есть табличное представление, которое запаздывает, когда есть несколько ячеек.Когда есть только одна ячейка, она работает гладко;однако при заполнении нескольких ячеек табличное представление ощущается медленно, иногда заикается и не так гладко.Я удалил распознаватели жестов и вместо этого изменил его на didSelectRowAt, однако внутри ячеек все еще есть задержка.Вот код для того, когда ячейки загружены:

  public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if queryComplete == true {
        if displayConvo == true {
            let cell = tableView.dequeueReusableCell(withIdentifier: "messageCell", for: indexPath as IndexPath)  as! messageTableViewCell
            cell.profileImage.image = nil
            cell.selectionStyle = UITableViewCell.SelectionStyle.none

            var convoContent: messagesViewController.Convo
            convoContent = convoList[indexPath.row]

            convoContent.itemHeroID = "\(String(describing: convoContent.convoID))"
            cell.name.heroID = "\(String(describing: convoContent.convoID))"
            cell.lastMessage.text = convoContent.lastMessage
            cell.backgroundColor = UIColor.clear
            cell.postText.text = convoContent.postContent

            if convoContent.revealedBool == true {
                cell.profileImage.isHidden = false
                cell.profileImage.heroID = "\(String(describing: convoContent.convoID))"
                cell.name.text = convoContent.name
                cell.timer.isHidden = true
                if convoContent.profileImage == "nil" || convoContent.profileImage == nil {
                    let url =  URL(string:"https://firebasestorage.googleapis.comasdjfjaisfdji")
                    let processor = RoundCornerImageProcessor(cornerRadius: cell.profileImage.frame.size.width / 2)
                    cell.profileImage.kf.setImage(with: url, placeholder: nil, options: [.processor(processor)])
                }

                else {
                    let url = URL(string: convoContent.profileImage!)
                    let processor = RoundCornerImageProcessor(cornerRadius: cell.profileImage.frame.size.width / 2)
                    cell.profileImage.kf.setImage(with: url, placeholder: nil, options: [.processor(processor)])

                }
            }

            else {
                cell.profileImage.isHidden = true
                cell.timer.isHidden = false
                cell.timer.isUserInteractionEnabled = false
                cell.timer.heroID = "\(String(describing: convoContent.convoID))"
                let postDuration = convoContent.timeOfDeletion! - Int(convoContent.time!)
                let currentTime =  Date().timeIntervalSince1970 * 1000
                let difference = Int(round(Double(convoContent.timeOfDeletion! - Int(currentTime))))
                let date = Date(timeIntervalSinceNow: TimeInterval(difference / 1000))
                cell.name.text = String(timeToDelete(date: date as NSDate, numericDates: false))

                let amountOfCircleCovered = (Double(((convoContent.timeOfDeletion!) - Int(currentTime))) / Double(postDuration)) * 100
                var timerColor: UIColor?
                switch amountOfCircleCovered {
                case 0..<30:
                    timerColor = UIColor (red: 252/255, green: 110/255, blue: 81/255, alpha: 1)
                case 30..<60:
                    timerColor = UIColor (red: 255/255, green: 215/255, blue: 0/255, alpha: 1)
                case 60..<100:
                    timerColor =  UIColor(red: 26/255, green: 152/255, blue: 252/255, alpha: 1.0)
                default:
                    timerColor =  UIColor(red: 26/255, green: 152/255, blue: 252/255, alpha: 1.0)
                }
                print(amountOfCircleCovered)
                cell.timer.models = [   PieSliceModel(value: Double(100 - amountOfCircleCovered), color: UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1)),
                                        PieSliceModel(value: Double(amountOfCircleCovered), color: timerColor!),
                ]

            }
            let lastMessageDate = Date(timeIntervalSince1970: TimeInterval(convoContent.timeOfLastMessage! / 1000))
            cell.timeOfLastMessage.text = String(timeAgo(date: lastMessageDate as NSDate, numericDates: false))
            return cell

            }
        else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "messageCell", for: indexPath as IndexPath)  as! messageTableViewCell

            cell.lastMessage.text = "No new messages"
            return cell
            }
    }
    else {
        let cell = tableView.dequeueReusableCell(withIdentifier: "messageCell", for: indexPath as IndexPath)  as! messageTableViewCell
        print ("loading")
        return cell
    }
}

Кроме того, я попытался переместить некоторые аспекты ячейки, чтобы их каждый раз можно было сбрасывать, помещая их в файл ячейки:

override func awakeFromNib() {
    super.awakeFromNib()

    profileImage.cornerRadius = profileImage.frame.size.width / 2
    profileImage.clipsToBounds = true
    profileImage.layer.borderColor = UIColor.white.cgColor
    profileImage.layer.borderWidth = 1

    timer.innerRadius = 0
    timer.outerRadius = timer.frame.width / 2
    timer.animDuration = 0.0
    timer.referenceAngle = 270
    timer.backgroundColor = UIColor.white
    postText.layer.zPosition = 1

    if !UIAccessibility.isReduceTransparencyEnabled {
        glossyView.backgroundColor = .clear

        let blurEffect = UIBlurEffect(style: .regular)
        let blurEffectView = UIVisualEffectView(effect: blurEffect)
        //always fill the view
        blurEffectView.frame = self.glossyView.bounds
        blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        glossyView.addSubview(blurEffectView) //if you have more UIViews, use an insertSubview API to place it where needed
    } else {
        glossyView.backgroundColor = .black
    }

    timer.selectedOffset = 0
    glossyView.clipsToBounds = true
    glossyView.cornerRadius = 12.0
    glossyView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]

    messageBackground.clipsToBounds = true
    messageBackground.cornerRadius = 12.0
    messageBackground.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
  //  glossyView.roundCornersView(corners: [.topLeft, .topRight], radius: 12.0)
   // messageBackground.roundCornersView(corners: [.bottomLeft,.bottomRight], radius: 12.0)
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
}

override func prepareForReuse() {
    profileImage.image = nil
    timer.isHidden = true
    timer.models = []

}

}

И все же, когда загружается несколько ячеек, табличное представление все еще отстает.Я удостоверился, что нет распознавателей жестов, поскольку эта ссылка предлагает, а также изображения загружаются с использованием библиотеки, поэтому я не уверен, почему ячейки все еще отстают.

1 Ответ

1 голос
/ 14 марта 2019

По сути, пользовательский интерфейс резко замедлил производительность.Я отключил круговой слой CA Layer для png изображений частично заполненных кругов и удалил все анимационные герои.В результате и приложение, и просмотр таблицы стали намного плавнее.

...