我在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];
}
}];
}
这是它的样子:http://www.youtube.com/watch?v=UR_vYAjhprE
尝试:
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
方法。
我发现了问题。我不得不在情节提要的文件检查器中停用"使用自动布局"。顺便说一句:这可能与iOS 7和XCode 5有关。