ivnsch / SwiftCharts

Easy to use and highly customizable charts library for iOS
Apache License 2.0
2.53k stars 410 forks source link

StackBars in TableViewCell difficult to tap #292

Closed dustinspengler closed 7 years ago

dustinspengler commented 7 years ago

I have created a calendar app which uses SwiftCharts to display a time bar like this:

img_6678

I nest the chart bars inside UITableViewCells. When i tap on the cells (not the event bar), I navigate to another view. Everything currently works great except when I tap directly on the bars themselves. It seems like there is a tapGestureRecognizer or something on the bars that is overriding the cell tap. Id like to either disable to tapRecognizer on the bar or have the tap trigger the segue. Any idea how I might do either?

dustinspengler commented 7 years ago

This is my code so far but it doesnt seem to work: screen shot 2017-09-10 at 4 18 57 pm 2

When i tap on the bar, the stackFrameSelectionViewUpdater runs, which changes the opacity of the bar, but it does not run the print statement.

ivnsch commented 7 years ago

Hm. Seems like a bug! Unfortunately I don't have time to fix this now, but feel free to give it a look and submit a pull request... the bar layers are straight forward (just custom views with tap handlers), shouldn't be difficult to debug. Sorry for the delay!

dustinspengler commented 7 years ago

I found a work around for now by adding a long tap gesture to my tableview like this:

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()
            }
        }
    }

For some reason if you tap and hold, it by-passes the ChartStackedBarsLayer tap handler. I'm guessing I did something weird with z-indexes or adding different views to a parent view or something along those lines, so this most likely is not be a bug with the framework. I'll update this post as I test it more.

Many thanks for the feedback and great framework!