ios – 如何删除UITableViewCell,使用淡入淡出效果并且没有红色删除按钮?

ios – 如何删除UITableViewCell,使用淡入淡出效果并且没有红色删除按钮?,第1张

概述在查看了无数的StackOverflow帖子后,没有什么能真正回答如何在淡入淡出和没有红色删除按钮的情况下删除UITableViewCell时使用滑动到关闭. 我的Tableviewcell看起来像一张卡片,因此删除按钮的红色框架打破了卡片形状的这些细胞的连续性和高度感. 这是我目前用来删除的代码,尽管UITableViewRowAnimation上有.fade,但它不会消失. func tabl 在查看了无数的StackOverflow帖子后,没有什么能真正回答如何在淡入淡出和没有红色删除按钮的情况下删除UItableVIEwCell时使用滑动到关闭.

我的tablevIEwcell看起来像一张卡片,因此删除按钮的红色框架打破了卡片形状的这些细胞的连续性和高度感.@H_419_3@

这是我目前用来删除的代码,尽管UItableVIEwRowAnimation上有.fade,但它不会消失.@H_419_3@

func tableVIEw(_ tableVIEw: UItableVIEw,shouldindentWhileEditingRowAt indexPath: IndexPath) -> Bool {    return false}func tableVIEw(_ tableVIEw: UItableVIEw,editingStyleForRowAt indexPath: IndexPath) -> UItableVIEwCellEditingStyle {    return .none}func tableVIEw(_ tableVIEw: UItableVIEw,commit editingStyle: UItableVIEwCellEditingStyle,forRowAt indexPath: IndexPath) {    if editingStyle == .delete {        self.pastOrders.remove(at: indexPath.row)        tableVIEw.deleteRows(at: [indexPath],with: .fade)    }}

这是我试图实现的行为的屏幕截图:@H_419_3@

@H_419_3@解决方法 输出3

//TO CHANGE "DELETE" Title colorfunc tableVIEw(_ tableVIEw: UItableVIEw,editactionsForRowAt indexPath: IndexPath) -> [UItableVIEwRowAction]? {        let toDelete = UItableVIEwRowAction(style: .normal,Title: "") { (action,indexPath) in            print("\n\n Delete item at indexPathDelete item at indexPath")        }        let deleteTextimg = swipeCellbuttons(labelText: "Delete",textcolor: UIcolor.darkGray,AlphaVal: 1.0)        toDelete.backgroundcolor = UIcolor(patternImage: deleteTextimg)        return [toDelete]  }func swipeCellbuttons(labelText : String,textcolor: UIcolor,AlphaVal: CGfloat) -> UIImage {     let commonWID : CGfloat = 40     let commonHei : CGfloat = 70 // ROW HEIGHT     let label = UILabel(frame: CGRect(x: 0,y: 0,wIDth: commonWID,height: commonHei))     label.text = labelText     label.textAlignment = .center     label.Font = UIFont.systemFont(ofSize: 11)     label.textcolor = textcolor.withAlphaComponent(AlphaVal)     UIGraphicsBeginImageContextWithOptions(CGSize(wIDth: self.vIEw.frame.wIDth,height: commonHei),false,UIScreen.main.scale)     let context = UIGraphicsGetCurrentContext()     context!.setFillcolor(UIcolor.clear.cgcolor) // YOU CAN GIVE YOUR BGcolor FOR DELETE button      context!.fill(CGRect(x: 0,wIDth: (self.vIEw.frame.wIDth) / 3,height: commonHei))     label.layer.render(in: context!)     //If you want to add image instead of text,uncomment below lines.     //Then,comment this "label.layer.render(in: context!)" line     //var img: UIImage = UIImage(named: "deleteIcon")!     //img.draw(in: CGRect(x: 0,wIDth: 30,height: 30))     let newImage: UIImage = UIGraphicsGetimageFromCurrentimageContext()!     UIGraphicsEndImageContext()     return newImage }

输出2:@H_419_3@

// INSIDE CELL FOR ROW AT INDEXPATH// COMMENT THIS liNE//cell.addGestureRecognizer(swipeGesture)// CELL FADE WILL NOT WORK HEREfunc tableVIEw(_ tableVIEw: UItableVIEw,Title: "   ") { (action,indexPath) in            print("\n\n Delete item at indexPathDelete item at indexPath")        }        toDelete.backgroundcolor = .white        return [toDelete]  }

输出1:@H_419_3@

// GLOBAL DECLaraTIONvar gotCell : DefaulttableVIEwCell?var AlphaValue : CGfloat = 1.0var deletingRowIndpath = IndexPath()      // INSIDE CELL FOR ROW AT INDEXPATH //let cell = tableVIEw.dequeueReusableCell(withIDentifIEr: "default",for: indexPath) as! DefaulttableVIEwCell let cell = DefaulttableVIEwCell() // Add this line and comment above line. The issue is `dequeuingreusingcell`. In this method,it will stop dequeuing. But,we have to customise `UItableVIEwCell` in Coding.  let swipeGesture = UIPanGestureRecognizer(target: self,action: #selector(handleSwipe)) swipeGesture.delegate = self cell.addGestureRecognizer(swipeGesture) func handleSwipe(panGesture: UIPanGestureRecognizer) {    if panGesture.state == UIGestureRecognizerState.began {        let cellposition = panGesture.vIEw?.convert(CGPoint.zero,to: defTblVw)        let indpath = defTblVw.indexPathForRow(at: cellposition!)        deletingRowIndpath = indpath!        gotCell = defTblVw.cellForRow(at: indpath!) as! DefaulttableVIEwCell    }    if panGesture.state == UIGestureRecognizerState.changed    {        let isleftMoving = panGesture.isleft(theVIEwYouArePassing: (gotCell)!)        if isleftMoving == true        {            self.gotCell?.Alpha = self.AlphaValue            self.gotCell?.frame.origin.x = (self.gotCell?.frame.origin.x)! - 2.5            self.vIEw.layoutIfNeeded()            self.AlphaValue = self.AlphaValue - 0.005        }        else // ADD THIS ELSE CASE        {            self.AlphaValue = 1.0            self.gotCell?.Alpha = 1.0            UIVIEw.animate(withDuration: 0.8,animations: {                self.gotCell?.frame.origin.x = 0                self.vIEw.layoutIfNeeded()            }) { (value) in            }        }    }    if panGesture.state == UIGestureRecognizerState.ended    {        self.AlphaValue = 1.0        if (self.gotCell?.frame.origin.x)! < CGfloat(-(defTblVw.frame.size.wIDth - 90))        {            myArr.remove(at: (deletingRowIndpath.row))            defTblVw.beginUpdates()            defTblVw.deleteRows(at: [deletingRowIndpath],with: UItableVIEwRowAnimation.fade)            defTblVw.endUpdates()        }        else        {            UIVIEw.animate(withDuration: 0.8,animations: {                self.gotCell?.Alpha = 1.0                self.gotCell?.frame.origin.x = 0                self.vIEw.layoutIfNeeded()            }) { (value) in            }        }    }}func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {    return true}extension UIPanGestureRecognizer { func isleft(theVIEwYouArePassing: UIVIEw) -> Bool {    let veLocityVal : CGPoint = veLocity(in: theVIEwYouArePassing)    if veLocityVal.x >= 0 {          return false    }    else    {        print("Gesture went other")        return true    } }}

=============================@H_419_3@ 总结

以上是内存溢出为你收集整理的ios – 如何删除UITableViewCell,使用淡入淡出效果并且没有红色删除按钮?全部内容,希望文章能够帮你解决ios – 如何删除UITableViewCell,使用淡入淡出效果并且没有红色删除按钮?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1099326.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存