Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] support custom handler for gestures #148

Closed
liuxuan30 opened this issue Jun 12, 2015 · 14 comments
Closed

[feature request] support custom handler for gestures #148

liuxuan30 opened this issue Jun 12, 2015 · 14 comments

Comments

@liuxuan30
Copy link
Member

I looked at current swift code, seems like the gestures and private and I cannot provide custom handler to replace the default one?

Say if PieRadarChartViewBase has a doubleTapGestureRecognizer (which does not exist right now), the default behaviour is the zooming feature. Now I don't want zoom I want to double tap to be my own handler.

I think the complicated part is supporting both Objective-C and swift block. I am not sure is there any evil there. like retain cycle or others.

@danielgindi
Copy link
Collaborator

Of course you can. It behaves like any other UIView. You can explicitpy disable the gestures with the dedicated properties, or work with the gestureRecognizers array.

@liuxuan30
Copy link
Member Author

could you give the key word? How to provide the block? I don't see a place I can provide my own block via a API.

@liuxuan30
Copy link
Member Author

well I think I know what to ask: is there any public API to get the data set / xIndex etc. if I give a location (CGPoint)

What I want is I can provide a touch location, and want to get the dataSet and xIndex, etc. to know what value is double tapped.

@danielgindi
Copy link
Collaborator

danielgindi commented Jun 12, 2015 via email

@liuxuan30
Copy link
Member Author

I did, but it seems I have to write a function to get the data set or whatever given a location. I don't see a similar function do this in Utils. Just want to check if there is. I think this API is useful.

@liuxuan30
Copy link
Member Author

What I am looking for is like below:

    public func xIndexAtPoint(point: CGPoint) -> Int {
        var distance = distanceToCenter(x: point.x, y: point.y);
        // check if a slice was touched
        if (distance <= self.radius)
        {
            var angle = angleForPoint(x: point.x, y: point.y);

            if (self.isKindOfClass(PieChartView))
            {
                angle /= _animator.phaseY;
            }

            var index = indexForAngle(angle);

            // check if the index could be found
            if (index < 0)
            {
                return NSNotFound;
            }
            else
            {
                return index;
            }
        } else {
            return NSNotFound;
        }
    }

Do you think such kind of functions is useful for other people?

@danielgindi
Copy link
Collaborator

danielgindi commented Jun 12, 2015 via email

@liuxuan30
Copy link
Member Author

yeah I am using it. But I am wondering if such functions can be useful for others.

@danielgindi
Copy link
Collaborator

danielgindi commented Jun 12, 2015 via email

@zxhfirefox
Copy link

@danielgindi , I think all the gesture handler function should be internal, or even public.
Because, although we can get the gesture from the view, and change it with our own handler, or delegate and other properties, but there are some private properties, that our own handler will be very hard to make it consistent, and we want to reuse the default handler. So we can do in our own handler like this

override func tapGestureRecognized(recognizer:UITapGestureRecognizer)
{
       super.tapGestureRecognized(recognizer)
       // our own code here.
}

@liuxuan30
Copy link
Member Author

This is the PR #268

Better to let the gestures itself as internal discussed in PR, and you can have your own private gesture handlers.

@zxhfirefox
Copy link

@liuxuan30 Great!

@ashish1703
Copy link

@zxhfirefox i want to override doubletap on all say a batchart. Is there a way i can do it?
What i am doing currently with no result whatsoever is:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touch:)];
[tap setNumberOfTapsRequired:1]; // Set your own number here
[tap setDelegate:self]; // Add the protocol

add the gesture to the chartview.

Any help in this respect will be world of good for me.

@ghost
Copy link

ghost commented Aug 7, 2017

You cannot have multiple tap gesture recognizers of the same type on the same view in iOS. They will conflict. Research it. It would be great if the library allowed us to add our own custom tap handler or gave us a tapped hook method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants