简体   繁体   中英

Rotate UIView on a Pivot

Please could you tell me how to rotate a UIView (with a pie chart on) as if its on a pivot. It will only rotate once the user has flicked the view.

You'd use something like this:

- (void)spin
{
        CABasicAnimation *fullRotation;
        fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        fullRotation.fromValue = [NSNumber numberWithFloat:0];
        fullRotation.toValue = [NSNumber numberWithFloat:M_PI * 360 / 180.0];
        fullRotation.duration = 0.25;
        fullRotation.repeatCount = 1;
        [self.view.layer addAnimation:fullRotation forKey:@"360"];
}

Merely call the spin method when you want to spin 360º. Adjust as needed to spin more, less, faster, slower, etc.

EDIT: Should note, that in the above code, the view property is the one we're rotating, in case it wasn't obvious. So change self.view to whatever view you want to rotate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM