Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example for TableView #152

Open
noorbhatia opened this issue Jan 5, 2024 · 0 comments
Open

example for TableView #152

noorbhatia opened this issue Jan 5, 2024 · 0 comments

Comments

@noorbhatia
Copy link

Can this be added as a TableViewCell? If so can you add an example to do that? I am not able to make it work

This is my TableViewCell

//
//  SwipeableCardTableViewCell.swift
//  Hunbun
//
//  Created by noor on 05/01/24.
//

import UIKit
import ZLSwipeableViewSwift

class SwipeableCardTableViewCell: UITableViewCell {

    var swipeableView: ZLSwipeableView!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setup()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setup()
    }

    func setup() {
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        configureSwipeableView()
        layoutSwipeableView()
    }

    func configureSwipeableView() {
        swipeableView = ZLSwipeableView()
        swipeableView.translatesAutoresizingMaskIntoConstraints = false
        contentView.addSubview(swipeableView)

        swipeableView.didStart = { _, _ in
            print("Did start swiping view")
        }

        swipeableView.nextView = { [weak self] in
            return self?.nextCardView()
        }

        swipeableView.didEnd = { _, location in
            print("Did end swiping view at location: \(location)")
        }

        swipeableView.didSwipe = { _, direction, vector in
            print("Did swipe view in direction: \(direction), vector: \(vector)")
        }

        swipeableView.didCancel = { _ in
            print("Did cancel swiping view")
        }

        swipeableView.didTap = { _, location in
            print("Did tap at location \(location)")
        }

        swipeableView.didDisappear = { _ in
            print("Did disappear swiping view")
        }
    }

    func layoutSwipeableView() {
       swipeableView.anchor(top:contentView.topAnchor, left: contentView.leftAnchor, bottom: contentView.bottomAnchor, right: contentView.rightAnchor)
    }

    func nextCardView() -> UIView? {
        // Implement your logic to create the next card view
        // Example:
       let cardView = UIView(frame: swipeableView.bounds)
        cardView.backgroundColor = .blue
        return cardView
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant