Giter Club home page Giter Club logo

Comments (10)

ivnsch avatar ivnsch commented on May 28, 2024

You have to set the gesture recognizer programmatically, here for example you can see how to do it. IBAction doesn't work in this case because the views are generated programmatically, not in storyboard.

About the error, could you post the message? What I see at first glance is 1. you have to declare self in the touch handler as weak, like this:

bubbleView.touchHandler = {[weak self] view in (...)

Then, because it's a weak variable, treat it as an optional self?.performSegueWithIdentifier.

Otherwise you would get there a memory leak. This should not be causing the crash though.

Another issue I see is that you are assigning the chartPoint to a local variable, you probably want to use your instance variable chartPointDetail instead.

from swiftcharts.

mac389 avatar mac389 commented on May 28, 2024

My scatter plot now recognizes two touches. The scatter plot displays a dialog box when the user taps. It switches to a detail view when the user taps and holds if the user holds for at least one second.

I used chartPointDetail. Thanks for pointing that out.

I avoided the crash by moving the function that handles UILongPressGesture outside touchHandler. It looks like the crash happened because putting the function to handle tap and holds inside the function to handle taps led to calls to the function to handle tap and holds without the state of UILongPressGesture being set.

Updated Gist: https://gist.github.com/0a5191ece2b870b33658.git

from swiftcharts.

mac389 avatar mac389 commented on May 28, 2024

Why does this code fail to detect the currently pressed button during a tap and hold gesture? (Gist: https://gist.github.com/0a5191ece2b870b33658.git)

It always chooses the last member of ChartPointBubble. I do not know how to update selectedIndex, assuming this approach is the best way to handle two touch events. I believe my error is that bubblesLayer.

from swiftcharts.

ivnsch avatar ivnsch commented on May 28, 2024
  1. I would add the long touch recognizer to the bubbles. You can do this in the MyBubbleView initializer, and add a new handler to this class analogous to touchHandler. Then, in your longPressed, which would be now in MyBubbleView, call your new handler.
  2. In the long touch handler closure, which you can pass now to MyBubbleView thanks to 1. you have access to the index of the touched point, and can set your selectedIndex variable (you also can just store the chartpoint as instance variable, instead of the index, if all you want is to pass the chartpoint itself - index is useful if you want to get original model object, which you used to generate the chartpoint).

from swiftcharts.

mac389 avatar mac389 commented on May 28, 2024

XCode gives me an error when I try to move longPressed into MyBubbleView that performSegueWithIdentifier is an unknown method. I think this is because MyBubbleView inherits from UIView rather than UIViewController?

How can I address this? Changing MyBubbleView to inherit from UIViewController creates many problems, for example the init method becomes out of place. Along the same lines, what do I do with prepareForSegue? My understanding is I can't move it to MyBubbleView because UIView doesn't have a prepareForSegue function.

Perhaps in MyBubbleView, longPressed should look like

   var longPressHandler: ((MyBubbleView) -> ())?
   var gesture: UILongPressGestureRecognizer?
  var package: AnyObject?
   ...
    func longPressed(longPress: UIGestureRecognizer){
         if (longPress.state == UIGestureRecognizerState.Ended)
         {
              longPressHandler{ something here}
             AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
             //self.performSegueWithIdentifier("showDetail", sender: self.chartPoints[self.selectedIndex!])

         }
     }

I assume the closure in EcosystemMasterViewController (the main class of that file) should look like:

 bubbleView.longPressHandler { [weak self] view in 

         bubbleView.add(gesture!)
         self.package = self.ChartPoints[self.chartPointsModel.charIndex]

 }

I apologize for the extended question. I am still learning both Swift and SwiftCharts.

from swiftcharts.

ivnsch avatar ivnsch commented on May 28, 2024

You don't have to put any code in longPressed except calling the handler function... your custom logic (performSegueWithIdentifier, etc.) goes in the handler function...

from swiftcharts.

mac389 avatar mac389 commented on May 28, 2024

You mean the following suffices?

 func longPressed(longPress: UIGestureRecognizer){
      self.longPressHandler(self)

}

from swiftcharts.

ivnsch avatar ivnsch commented on May 28, 2024

Yes, that's why I wrote analogous to touchHandler.

from swiftcharts.

mac389 avatar mac389 commented on May 28, 2024

I am still missing something. A tap and hold leads to no transition now. I think I followed your suggestions. There is no transition whether GestureRecognizer is added to bubbleView or EcosystemMasterViewController

Gist: https://gist.github.com/mac389/0a5191ece2b870b33658

from swiftcharts.

ivnsch avatar ivnsch commented on May 28, 2024

Put the addGestureRecognizer in the initializer, directly after you create the recognizer. Right now you have it in the handler closure, so it will never be added and the closure never executed.

from swiftcharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.