0
我曾嘗試過各種方法,無法弄清楚如何實現這一點。我在互聯網上搜索了很多,但無法弄清楚。多次旋轉圖像並停在所需的程度?
我有一個ImageView(一個旋轉的輪子),我想旋轉360度10次(這只是讓用戶感覺快速轉動輪子),然後我想旋轉它特別值是90度(但可能會有所不同)。
此動畫完成後,我想將ImageView恢復到初始位置。
我該如何做到這一點? 在此先感謝。
我曾嘗試過各種方法,無法弄清楚如何實現這一點。我在互聯網上搜索了很多,但無法弄清楚。多次旋轉圖像並停在所需的程度?
我有一個ImageView(一個旋轉的輪子),我想旋轉360度10次(這只是讓用戶感覺快速轉動輪子),然後我想旋轉它特別值是90度(但可能會有所不同)。
此動畫完成後,我想將ImageView恢復到初始位置。
我該如何做到這一點? 在此先感謝。
以及我發現如何做到這一點。 我用下面的方法360度旋轉10次,然後按特定的程度旋轉。
-(void)rotate:(int)degreeToRotate
{
CGFloat radians = (M_PI/180) * degreeToRotate;
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations: ^{
//configuring to rotate 360 degree 10 times
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 10;
[_scoreImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
} completion:^(BOOL finished) {
//rotate by particular degree
[ UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
// -radians, to ensure clockwise rotation
self.scoreImageView.transform = CGAffineTransformMakeRotation(-radians);
} completion:^(BOOL finished) {
//method call to reset image original position
[self performSelector:@selector(resetPosition) withObject:nil afterDelay:3];
}];
}];
}
以下方法用於將圖像重置爲原始位置。
-(void)resetPosition
{
[UIView animateWithDuration:0.2 animations:^() {
self.scoreImageView.transform = CGAffineTransformIdentity;
}];
}
你是如何旋轉圖像視圖? – AdamPro13
我用CGAffineTransformMakeRotation旋轉。我也嘗試過[CABasicAnimation animationWithKeyPath:@「transform.rotation.z」] –
嘗試在末尾應用'CGAffineTransformIdentity'將其返回到原始狀態。 – AdamPro13