我在iOS上旋转我的UIView时遇到问题。当我开始旋转动画时,我的视图总是跳到一个新位置并开始在那里旋转。
我的转变:
originalState = myRotatingView.transform;
startAnimation = CGAffineTransformRotate(originalState, degreesToRadians(-50));
forwardAnimation = CGAffineTransformRotate(originalState, degreesToRadians(50));
backwardAnimation = CGAffineTransformInvert(forwardAnimation);
我的方法:
- (void) stopAnimation {
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
myRotatingView.transform = originalState;
} completion:nil];
rotatingViewState = STOPPED;
}
- (void) startAnimation {
CGAffineTransform transform;
if (rotatingViewState == STOPPED) {
rotatingViewState = FORWARD;
transform = startAnimation;
} else {
if (rotatingViewState == BACKWARDS) {
rotatingViewState = FORWARD;
transform = backwardAnimation;
} else {
rotatingViewState = BACKWARDS;
transform = forwardAnimation;
}
}
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
myRotatingView.transform = transform;
} completion:^(BOOL finished){
if(finished) {
[self startAnimation];
}
}];
}
答案 0 :(得分:0)
尝试:
originalState = myRotatingView.transform;
startAnimation = CGAffineTransformRotate(originalState, degreesToRadians(-50));
forwardAnimation = CGAffineTransformRotate(startAnimation, degreesToRadians(50));
backwardAnimation = CGAffineTransformRotate(forwardAnimation, degreesToRadians(-50));
并将UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
作为options
参数传递给animateWithDuration:delay:options:animations:completion
方法。
答案 1 :(得分:0)
我发现了问题。我不得不在故事板的文件检查器中停用“使用Autolayout”。 顺便说一句:这可能与iOS 7和XCode 5有关。