2014-02-19 47 views
0

我在iOS上旋转我的UIView时遇到了问题。当我开始动画旋转时,我的视图总是跳到一个新的位置并开始旋转。Objective C 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

回答

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方法。

+0

对不起,这不起作用。将startAnimation设置为从startAnimation变换只是将动画移回起点。此外,UIView从头开始跳,因此我的startAnimation肯定有问题。 一旦动画开始,它就可以正常工作而不会跳来跳去。 – nurbs999

+0

并且您通过了UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState作为方法的“选项”参数? –

+0

是的,我做了......该死的最小字符计数器;) – nurbs999

0

我发现了这个问题。我必须在故事板的文件检查器中停用“使用Autolayout”。 btw:这可能与iOS 7和XCode 5有关。