Comments (10)
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.
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.
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.
- 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.
- 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.
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.
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.
You mean the following suffices?
func longPressed(longPress: UIGestureRecognizer){
self.longPressHandler(self)
}
from swiftcharts.
Yes, that's why I wrote analogous to touchHandler.
from swiftcharts.
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.
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)
- Static library
- Temporarily hide lines in Line chart
- What's the correct way to set contentView background color and border? HOT 1
- Is this kind of y axis layout possible:
- Extending Views to create custom views isn't working due to file private and internal properties
- How to overlay a layer of labels?
- Axis disappear after coming back from background
- X Y points in horizontal bar chart keeps moving rights; when the y axis labels length (text) is more
- Swift 5
- Changing axis values
- X values not adding properly
- Axis Labels not showing up HOT 2
- ChartLabelSettings() ignoring supplied font color, always defaults to black HOT 1
- SPM Support?
- Problem building on new MacBook
- SPM not working properly due to missing TAG HOT 1
- x, y Axis didn't show in the Chart HOT 2
- ChartPointsBubbleLayer not draws properly HOT 1
- how to dynamic live update line chart
- How can i make xAxisLabel to get multiple data instead of one value for one xAxisLabel ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftcharts.