在类似于 ios 通知中心的表格视图中编辑操作

萨提亚·塔鲁玛尼

我需要开发一个表视图,在行上进行编辑操作,这些操作看起来类似于 iOS 通知中心上的行。
到目前为止我使用的资源,说我只能编辑编辑操作的背景颜色和宽度。我想要的是类似于 iOS 通知中心通知的自定义外观。

见注释部分。这就是我要的。

见注释部分

这是我到目前为止所管理的:|

这是我到目前为止所管理的:|

任何帮助/指导将不胜感激!
提前致谢!

萨提亚·塔鲁玛尼

我最终创建了自己的视图作为表格视图单元格的一部分并添加了自定义动画..

示例代码:
在我的 tableViewController 中:

override func viewDidLoad() {
    super.viewDidLoad()
    ....

    let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(handleTap))
    tableView.addGestureRecognizer(tapGesture)

    let leftSwipeGesture = UISwipeGestureRecognizer.init(target: self, action: #selector(handleLeftSwipe(_:)))
    leftSwipeGesture.direction = .left
    tableView.addGestureRecognizer(leftSwipeGesture)

    let rightSwipeGesture = UISwipeGestureRecognizer.init(target: self, action: #selector(handleRightSwipe(_:)))
    rightSwipeGesture.direction = .right
    tableView.addGestureRecognizer(rightSwipeGesture)
}

func handleTap(_ gestureRecognizer: UISwipeGestureRecognizer) {
    let point = gestureRecognizer.location(in: self.tableView)
    if let indexPath = self.tableView.indexPathForRow(at: point) {
        var shouldSelectRow = false
        if indexPathBeingEdited != nil {
            if indexPath == indexPathBeingEdited {
                shouldSelectRow = true
            } else {
                //handle close of the cell being edited already
                if let previousEditedCell = tableView.cellForRow(at: indexPathBeingEdited!) as? NotificationCenterTableViewCell {
                    previousEditedCell.closeEditActions()
                    indexPathBeingEdited = nil
                }
            }
        } else {
            shouldSelectRow = true
        }
        if shouldSelectRow {
            tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle)
            tableView(tableView, didSelectRowAt: indexPath)
        }
    }
}

func handleLeftSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) {
    let point = gestureRecognizer.location(in: self.tableView)
    if let indexPath = self.tableView.indexPathForRow(at: point) {
        if indexPathBeingEdited != nil {
            if indexPath == indexPathBeingEdited {
                //Do nothing
            } else {
                //handle close of the cell being edited already
                if let previousEditedCell = tableView.cellForRow(at: indexPathBeingEdited!) as? NotificationCenterTableViewCell {
                    previousEditedCell.closeEditActions()
                    indexPathBeingEdited = nil
                }
            }
        }
        //proceed with left swipe action
        if let cell = tableView.cellForRow(at: indexPath) as? NotificationCenterTableViewCell {
            cell.handleLeftSwipe(gestureRecognizer)
            let notification = notificationsArray[indexPath.section].notificationItems[indexPath.row]

            //Update the title of Read button
            if notification.isNotificationRead {
                cell.readUnreadButtonLabel.text = "Unread"
            } else {
                cell.readUnreadButtonLabel.text = "Read"
            }
            indexPathBeingEdited = indexPath
        }
    }
}

func handleRightSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) {
    let point = gestureRecognizer.location(in: self.tableView)
    if let indexPath = self.tableView.indexPathForRow(at: point) {
        if indexPathBeingEdited != nil {
            if indexPath == indexPathBeingEdited {
                if let cell = tableView.cellForRow(at: indexPath) as? NotificationCenterTableViewCell {
                    cell.closeEditActions()
                    indexPathBeingEdited = nil
                    //Update the title of Read button
                    cell.readUnreadButtonLabel.text = "Read"
                }
            } else {
                //handle close of the cell being edited already
                if let previousEditedCell = tableView.cellForRow(at: indexPathBeingEdited!) as? NotificationCenterTableViewCell {
                    previousEditedCell.closeEditActions()
                    indexPathBeingEdited = nil
                    //Update the title of Read button
                    previousEditedCell.readUnreadButtonLabel.text = "Read"
                }
            }
        }
    }
}

在我的表格视图单元格中:

    func handleLeftSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) {
    if !isBeingEdited {
        //Action to open the edit buttons
        UIView.animate(withDuration: 0.5, animations: {
            self.notificationHolderViewLeadingConstraint.constant -= 248
            self.notificationHolderViewTrailingConstraint.constant -= 248

            self.editActionsView.isHidden = false
            self.layoutIfNeeded()
        }, completion: { (success) in

        })
        isBeingEdited = true
    }
}

func closeEditActions() {
    if isBeingEdited {
        //Action to open the edit buttons
        UIView.animate(withDuration: 0.5, animations: {
            self.notificationHolderViewLeadingConstraint.constant += 248
            self.notificationHolderViewTrailingConstraint.constant += 248

            self.editActionsView.isHidden = true
            self.layoutIfNeeded()
        }, completion: { (success) in

        })
        isBeingEdited = false
    }
}   


 override func draw(_ rect: CGRect) {
    if let viewToRound = editActionsView {
        let path = UIBezierPath(roundedRect:viewToRound.bounds,
                                byRoundingCorners:[.topRight, .topLeft, .bottomRight, .bottomLeft],
                                cornerRadii: CGSize(width: 20, height:  20))

        let maskLayer = CAShapeLayer()

        maskLayer.path = path.cgPath
        viewToRound.layer.mask = maskLayer
    }
}    

仅供参考,我有我的编辑按钮,即阅读/查看/清除添加到editActionsView。相应的操作与我的 tableViewCell 类中的 IBActions 相关联。

结果是这样的:

最后看

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

创建类似于iOS子视图的Android子视图

来自分类Dev

iOS正在播放类似于音乐/ Spotify应用程序的视图

来自分类Dev

如何在 iOS 中创建类似于 yelp 的复杂滚动视图?

来自分类Dev

类似于通知中心的东西吗?

来自分类Dev

类似于dplyr的行操作

来自分类Dev

XSLT,类似于“ flatmap”的操作

来自分类Dev

集合视图中的类似于Tableview的动画?

来自分类Dev

类似于Android的iOS上的溢出菜单

来自分类Dev

类似于Android的iOS上的溢出菜单

来自分类Dev

iOS:设计WheelView,类似于UITableView

来自分类Dev

类似于StackExchange / Facebook的通知框定位

来自分类Dev

类似于存折的下拉视图类

来自分类Dev

使软键盘的行为类似于Android中的IOS

来自分类Dev

ios导航栏色调颜色(类似于facebook应用)

来自分类Dev

iOS是否具有类似于Android的RecyclerView的功能?

来自分类Dev

类似于iOS的半透明模态,模糊了其背后的背景

来自分类Dev

类似于在ios7中打开应用的动画

来自分类Dev

使用Qt获得类似于iOS7的模糊效果

来自分类Dev

在iOS 7上创建类似于Evernote的可拉伸UICollectionView

来自分类Dev

UITextView与其他元素(类似于Evernote)iOS

来自分类Dev

iOS应用程序中的MVC设计类似于Whatsapp

来自分类Dev

创建类似于iOS7选择菜单的菜单

来自分类Dev

用于Debian的类似于画图的图形编辑器?

来自分类Dev

如何使表格单元的行为类似于UL LI?

来自分类Dev

如何在R中查看类似于表格样式的列表

来自分类Dev

Excel中表格的“标签”列,类似于Wordpress

来自分类Dev

MongoDB:类似于Snapchat的数据库通知模式

来自分类Dev

如何创建类似于JGrowl的用户通知消息

来自分类Dev

杀死类似于WhatsApp的应用程序后获得通知

Related 相关文章

热门标签

归档