Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用UICollectionView-Swift3重叠显示卡_Ios_Swift_Drag And Drop_Uicollectionview_Gestures - Fatal编程技术网

Ios 使用UICollectionView-Swift3重叠显示卡

Ios 使用UICollectionView-Swift3重叠显示卡,ios,swift,drag-and-drop,uicollectionview,gestures,Ios,Swift,Drag And Drop,Uicollectionview,Gestures,我试图以如下所示的重叠方式将卡片排列到UICollectionView中 我正在使用拖放手势将项目排序到UICollectionView单元格中 现在显示的卡没有重叠,拖放操作也很好 霉菌代码: class HandController: UIViewController, RAReorderableLayoutDelegate, RAReorderableLayoutDataSource { let game = Game.sharedInstance @IB

我试图以如下所示的重叠方式将卡片排列到UICollectionView中

我正在使用拖放手势将项目排序到UICollectionView单元格中

现在显示的卡没有重叠,拖放操作也很好

霉菌代码:

class HandController: UIViewController, RAReorderableLayoutDelegate, RAReorderableLayoutDataSource {    
    let game = Game.sharedInstance



    @IBOutlet weak var collectionView: UICollectionView!


    private var books = [CardViewButton]()
override func viewDidLoad() {
        debugPrint("?? Hand300Controller ?...")
        super.viewDidLoad()

        collectionView.backgroundColor = UIColor.clear
        title = "RAReorderableLayout"
        collectionView.register(BookCell.self, forCellWithReuseIdentifier: "cell")
        collectionView.delegate = self
        collectionView.dataSource = self
        (collectionView.collectionViewLayout as! RAReorderableLayout).scrollDirection = .horizontal
        let aScalars = "A".unicodeScalars
        let zScalars = "Z".unicodeScalars
        let aAsciiCode = aScalars[aScalars.startIndex].value
        let zAsciiCode = zScalars[zScalars.startIndex].value
        //books = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14"]/*
        game.deck?.shuffleRandom()
       // containerForCardTable.addSubview(Game.sharedInstance.table.cardTableView)
        for index in 0...12{

            //print(game.deck?.cards[index].value)
            game.deck?.cards[index].isFaceUp = true
            books.append(((game.deck?.cards[index])?.cardView.cardViewButton)!)
        }
}
 // collectionView delegate datasource

    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return books.count
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: 60.0, height: 100.0)
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsetsMake(0, 20.0, 0, 20.0)
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 15
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        var cell: BookCell
        cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! BookCell
        //book = CardView(frame:CGRect(x: 15.0, y: 30.0, width: bounds.width - 16.0, height: 30.0),)
        cell.book = CardViewButton(frame:books[(indexPath as NSIndexPath).item].frame,value:books[(indexPath as NSIndexPath).item].value,id:books[(indexPath as NSIndexPath).item].id,isFaceUp : true)
        //cell.book = books[(indexPath as NSIndexPath).item]

        cell.contentView.addSubview(cell.book)
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, at: IndexPath, willMoveTo toIndexPath: IndexPath) {
          let temp = books[at.row]
          books[at.row] = (books[toIndexPath.row])
          books[toIndexPath.row] = temp
    }

    func collectionView(_ collectionView: UICollectionView, at: IndexPath, didMoveTo toIndexPath: IndexPath) {
       // let book = books.remove(at: (toIndexPath as NSIndexPath).item)
       // books.insert(book, at: (toIndexPath as NSIndexPath).item)
    }

    func scrollTrigerEdgeInsetsInCollectionView(_ collectionView: UICollectionView) -> UIEdgeInsets {
        return UIEdgeInsetsMake(0, 50, 0, 50)
    }

    func scrollSpeedValueInCollectionView(_ collectionView: UICollectionView) -> CGFloat {
        return 15.0
    }
}

class BookCell: UICollectionViewCell {
    private var backCoverView: UIView!
    private var pagesView: UIView!
    private var frontCoverView: UIView!
    private var bindingView: UIView!
    var book: CardViewButton!
    /*var book: CardView? {
        didSet {
            titleLabel.text = book?.title
            color = book?.color
        }
    }*/
    var color: UIColor? {
        didSet {
            backCoverView.backgroundColor = getDarkColor(color, minusValue: 20.0)
            frontCoverView.backgroundColor = color
            bindingView.backgroundColor = getDarkColor(color, minusValue: 50.0)
        }
    }

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

    override init(frame: CGRect) {
        super.init(frame: frame)
        configure()
    }

    override func prepareForReuse() {
        super.prepareForReuse()
       // book.
    }

    private func configure() {
        backCoverView = UIView(frame: bounds)
        backCoverView.backgroundColor = getDarkColor(UIColor.white, minusValue: 20.0)
        backCoverView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        pagesView = UIView(frame: CGRect(x: 15.0, y: 0, width: bounds.width - 25.0, height: bounds.height - 5.0))
        pagesView.backgroundColor = UIColor.white
        pagesView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        frontCoverView = UIView(frame: CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height - 10.0))
        frontCoverView.backgroundColor = UIColor.red
        frontCoverView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        bindingView = UIView(frame: CGRect(x: 0, y: 0, width: 15.0, height: bounds.height))
        bindingView.backgroundColor = getDarkColor(backCoverView?.backgroundColor, minusValue: 50.0)
        bindingView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        bindingView.layer.borderWidth = 1.0
        bindingView.layer.borderColor = UIColor.black.cgColor
       }

    private func getDarkColor(_ color: UIColor?, minusValue: CGFloat) -> UIColor? {
        if color == nil {
            return nil
        }
        var r: CGFloat = 0
        var g: CGFloat = 0
        var b: CGFloat = 0
        var a: CGFloat = 0
        color!.getRed(&r, green: &g, blue: &b, alpha: &a)
        r -= max(minusValue / 255.0, 0)
        g -= max(minusValue / 255.0, 0)
        b -= max(minusValue / 255.0, 0)
        return UIColor(red: r, green: g, blue: b, alpha: a)
    }
}

如何在重叠显示中排列卡片,并为重叠设计进行拖放工作

我认为在github中,只需重新排列单元格即可。他没有重叠细胞。A/c给我,当你拖动任何单元格并将手指放在屏幕上时,它会自动安排在某个位置,但不会与任何人重叠。我还需要示例代码来实现它,垂直将更有帮助。如果完成了,请与我分享代码