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

How do I animate a rotation of 360 degrees or more? #5

Open
Sweeper777 opened this issue Aug 25, 2017 · 3 comments
Open

How do I animate a rotation of 360 degrees or more? #5

Sweeper777 opened this issue Aug 25, 2017 · 3 comments

Comments

@Sweeper777
Copy link

Currently, .rotate(angle: 360) does not seem to rotate the view at all. I expected it to keep rotating the view clockwise until it reaches its original position. Is this not how it was designed? I have this workaround for now, but it's not nice:

transform(duration: 0.1, transforms: [
        .rotate(angle: 180)
    ]).then(animation: transform(duration: 0.1, transforms: [
        .rotate(angle: 180)
    ]))
@rchatham
Copy link
Owner

rchatham commented Sep 8, 2017

Hey! Thanks for pointing that out. I'll have a fix in the works shortly. Will post an update when it's ready.

@rchatham
Copy link
Owner

rchatham commented Sep 10, 2017

For now this fix gives a nice syntax. These were new methods but I feel that you are probably right. I will look into better testing these methods. Right now they rely on Apple's default implementations but should perhaps be rethought for this library.

protocol Rotateable {
    func rotate360(duration: TimeInterval) -> Animate
}
extension Rotateable where Self: UIView { 
// extension UIView: Rotateable {
// ^ If you just want to make all views rotateable
    func rotate360(duration: TimeInterval) -> Animate {
        return Animate()
            .then(animation: rotate(duration: duration/2, angle: 180, options: [.curveEaseIn]))
            .then(animation: rotate(duration: duration/2, angle: 360, options: [.curveEaseOut]))
    }
}

This should get the desired effect you are looking for by calling, rotateableView.rotate360(duration: 1.0).perform().

@rchatham
Copy link
Owner

I'll leave this open until I get a better fix.

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

2 participants