【问题标题】:SwiftCharts StackBars in TableViewCell difficult to tapTableViewCell 中的 SwiftCharts StackBars 难以点击
【发布时间】:2017-09-15 17:57:09
【问题描述】:

我创建了一个日历应用程序,它使用 SwiftCharts 显示时间栏,如下所示:

我将图表栏嵌套在 UITableViewCells 中。当我点击单元格(而不是直接点击事件栏)时,我导航到另一个视图。目前一切都很好,除非我直接点击酒吧本身。似乎有一个 tapGestureRecognizer 或其他东西在覆盖单元格的条上。目前,当我点击该栏时,stackFrameSelectionViewUpdater 运行,这会改变栏的不透明度,但是,打印语句永远不会运行。 我想禁用栏上的 tapRecognizer 或让点击触发 segue。知道我该怎么做吗?

这是我当前的代码:

barStack = ChartStackedBarsLayer(xAxis: xAxis,
                             yAxis: yAxis,
                             innerFrame: innerFrame,
                             barModels: allDayEventBar,
                             horizontal: true,
                             barWidth: 500,
                             settings: chartviewSettings,
                             stackFrameSelectionViewUpdater: ChartViewSelectorAlpha(selectedAlpha: 1, deselectedAlpha: 0.75),
                            tapHandler: {tappedBar in
                                print("user tapped bar")
                                //run segue
                            })

这是关于该问题的 github 帖子:StackBars in TableViewCell difficult to tap

【问题讨论】:

    标签: swift uitableview swiftcharts


    【解决方案1】:

    这可能是由于我在不知情的情况下通过在不同的 ViewController 中实例化图表,然后将其附加到父 ViewController 中的视图而创建的分层问题引起的。虽然我从来没有解决它,但找到了一个像这样的长按手势识别器的体面工作:

    let longPressGesture:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongPress(_:)))
    longPressGesture.minimumPressDuration = 0.3 
    longPressGesture.delegate = self
    self.usersTableVew.addGestureRecognizer(longPressGesture)
    
     func  handleLongPress(_ longPressGestureRecognizer: UILongPressGestureRecognizer) {
            if longPressGestureRecognizer.state == UIGestureRecognizerState.began {
                let touchPoint = longPressGestureRecognizer.location(in: self.view)
                if let indexPath = self.usersTableVew.indexPathForRow(at: touchPoint) {
                    let cellData = self.homeTableData[indexPath.section][indexPath.row]
                    GlobalNavDelegate.homeVCDelegate!.selectedName = cellData.name
                    GlobalNavDelegate.homeVCDelegate!.segueToEditPersonCal()
                }
            }
        }
    

    如果您对此感兴趣,请查看github post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-31
      • 2020-05-21
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多