TableViewCell上的Swift Show重叠按钮

时间:2018-04-22 09:53:24

标签: swift uitableview

我在TableViewCell中有一个按钮,重叠了欢迎TableViewCell。视图加载时看起来很好,但是当我向下滚动桌面视图并向上滚动时,按钮会被下一个tableviewcell切断。

我找到了一个hack来使消息TableViewCell的背景清晰,但是,按钮的底部仍然无法点击。

有没有办法将按钮的优先级设置在下一个按钮之上?

enter image description here

enter image description here

HomeTableViewController.swift

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    switch indexPath.section {
    case 0:
        let cell = tableView.dequeueReusableCell(withIdentifier: "heroCell", for: indexPath) as! HeroTableViewCell
        heroCell = cell
        cell.separatorInset = UIEdgeInsets(top: 0, left: 10000, bottom: 0, right: 0)
        return cell
    case 1:
        let cell = tableView.dequeueReusableCell(withIdentifier: "welcomeCell", for: indexPath) as! WelcomeTableViewCell
        // Set Intro Name
        if let user = Auth.auth().currentUser {
            // User is signed in

            // References to firebase
            let userFS = Firestore.firestore().collection("users")

            // Set the navigation title to users name
            userFS.document(user.uid).getDocument { (document, error) in
                if let userInfo = document {
                    let firstName = userInfo["firstName"] as! String
                    cell.introLabel.text = "Hey, \(firstName)"
                } else {
                    print("User name does not exist")
                }
            }
        }
        return cell
    case 2:
        let cell = tableView.dequeueReusableCell(withIdentifier: "tripsCell", for: indexPath) as! TripTableViewCell
        return cell
    case 3:
        let cell = tableView.dequeueReusableCell(withIdentifier: "suggestionsCell", for: indexPath) as! SuggestionTableViewCell
        return cell
    default:
        let cell = tableView.dequeueReusableCell(withIdentifier: "popularsCell", for: indexPath) as! PopularTableViewCell
        return cell
    }
}

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    switch indexPath.section {
    case 0: return 425
    case 1: return 200
    case 2: return 400
    case 3: return 400
    default: return 400
    }
}

  override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 425
}

HeroTableViewCell.swift

class HeroTableViewCell: UITableViewCell {

// MARK: - Outlets
@IBOutlet weak var heroImage: UIImageView!
@IBOutlet weak var heroImageViewTopConstraint: NSLayoutConstraint!

@IBOutlet weak var planTripButton: SpringButton!

// MARK: - Variables
let notification = UINotificationFeedbackGenerator()

override func awakeFromNib() {
}

// MARK: - Actions
@IBAction func addTripButtonPressed(_ sender: UIButton) {
    planTripButton.animation = "pop"
    planTripButton.animate()
    notification.notificationOccurred(.success)
}

}

1 个答案:

答案 0 :(得分:0)

如果我正确理解您的问题,您希望+按钮悬停在UITableView上,以便无论用户滚动到哪个单元格都可以点击它?

在下图中,我将我的操作按钮(视图右上角的铅笔)放在视图层次结构中与我的tableView相同的级别。因此,当用户滚动时,该按钮始终可见,用户可以随时点击。

请注意Action Button相对于Document outline中tableView的位置。它处于同一水平。它不是tableView的子视图。

enter image description here