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

Rotate programmatically #1

Open
pabermod opened this issue Mar 10, 2016 · 4 comments
Open

Rotate programmatically #1

pabermod opened this issue Mar 10, 2016 · 4 comments

Comments

@pabermod
Copy link

Hi,

Thanks for this great Rotatory Wheel.
I'm trying to rotate the wheel programmatically (on a UWP App), so when a user rotates it manually it keeps spinning for a defined amount of time

I'm kind of new to Manipulation...

How can I achieve it?

Thanks

@pabermod
Copy link
Author

I managed to do it when a button is clicked, by creating public properties for the DoubleAnimation and the StoryBoard.

Then in the click event of a button:

private void Button_Click(object sender, RoutedEventArgs e)
        {
            rotaryWheelDemo.Storyboard.Stop();

            Random Rnd = new Random();
            int Selected = Rnd.Next(0, rotaryWheelDemo.Slices.Count() - 1);
            int Angle = 360 / rotaryWheelDemo.Slices.Count();
            rotaryWheelDemo.Animation.To = 360 * 4 + rotaryWheelDemo.Angle + Angle * Selected;
            rotaryWheelDemo.Animation.Duration = new Duration(new TimeSpan(0, 0, 3));
            CircleEase CE = new CircleEase();
            CE.EasingMode = EasingMode.EaseOut;
            rotaryWheelDemo.Animation.EasingFunction = CE;
            rotaryWheelDemo.Storyboard.Begin();
        }

This could easily be made by creating a public method in RotatoryWheel like public void Rotate(double Degrees, TimeSpan duration)

But what i also wnat to do is what I stated in my previous post, I don't see the way to achieve it

Edited: Added random selection angle

@jpoon
Copy link
Owner

jpoon commented Mar 10, 2016

The layoutRoot_ManipulationCompleted is where the callback happens when a user releases the wheel. During that callback, you can adjust the animation to make it longer or to change the final position.

@pabermod
Copy link
Author

The problem in the layoutRoot_ManipulationComplete event is that ir fires when wheel rotation stops, not when when I release the finger/mouse.

I almost achieved by doing this:

        private void layoutRoot_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            storyBoard.Stop();

            Angle = QuadrantHelper.GetAngle(e.Position, RenderSize);
            // If it is not and intertia is occuring, stop the manipulation.
            if (e.IsInertial)
            {
                //Animation.From = Angle;
                Animation.To = 360 * 4 + Angle;
                Animation.Duration = new Windows.UI.Xaml.Duration(new System.TimeSpan(0, 0, 3));
                CircleEase CE = new CircleEase();
                CE.EasingMode = EasingMode.EaseOut;
                Animation.EasingFunction = CE;
                e.Complete();
                storyBoard.Begin();
            }
        }

and commenting the content of the layoutRoot_ManipulationCompleted event

It works good the first time, but the successive times I spin it if I start dragging the Wheel slowly it suddeny changes the angle like 90º and then speens correctly

Cheers

@ersuman
Copy link

ersuman commented Aug 29, 2017

Try this for rotating wheel programmatically
https://github.com/ersuman/RotaryWheel/tree/ersuman-patch-1

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

3 participants