Objective C UIView转换为旋转

时间:2014-02-19 22:03:05

标签: ios objective-c uiview rotation translate-animation

我在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

2 个答案:

答案 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有关。