2012-07-10 5 views
4

나는이 미친 코드를 가지고있다. Core Animation으로 어떻게 애니메이트하면 코드가 적어 질까요? "흔들림"애니메이션을 수행하기 위해 some code이 발견되었지만 3D로되어 있습니다.보기가 좌우로 움직이기를 원합니다. 애니메이션이 측면에서 튀는 것을 원하지 않습니다.UIView 프레임 애니메이션 "흔들림"

[UIView animateWithDuration:0.1f 
       animations:^{ 
        CGRect frame = tableView.frame; 
        frame.origin.x -= 4; 
        tableView.frame = frame; 
       } completion:^(BOOL finished) { 
        [UIView animateWithDuration:0.1f 
            animations:^{ 
             CGRect frame = tableView.frame; 
             frame.origin.x += 4; 
             tableView.frame = frame; 
            } completion:^(BOOL finished) { 
             [UIView animateWithDuration:0.1f 
                 animations:^{ 
                  CGRect frame = tableView.frame; 
                  frame.origin.x -= 4; 
                  tableView.frame = frame; 
                 } completion:^(BOOL finished) { 
                  [UIView animateWithDuration:0.1f 
                       animations:^{ 
                        CGRect frame = tableView.frame; 
                        frame.origin.x = 0; 
                        tableView.frame = frame; 
                      } completion:^(BOOL finished) { 
                        // Nothing 
                      } 
                   ]; 
                 } 
             ]; 
            } 
        ]; 
       } 
]; 
+0

시도를 [이 질문의 대답 (http://stackoverflow.com/questions/929364/how-to-create-iphones-wobbling-icon-effect), 내가 사용 그것과 위대한 작품. –

+0

나는 어느쪽으로도 가고 있지 않다. I * only * 뷰의 위치를 ​​가로로 앞뒤로 움직이기 원합니다. 흔들 리거나 흔들 리기를 원하지 않습니다. 그래도 고마워! – runmad

+0

비슷한 방법을 사용할 수도 있습니다. 회전을 변환에서 변환으로 변경하십시오. –

답변

0

This question은 반복 모션 애니메이션을 수행하는 매우 간결한 방법입니다. 회전 흔들기에 사용했지만 번역에 변환을 적용 할 수 있습니다.

8

누군가가 넘어지면이 질문을 따르고 싶습니다. 지금 키 프레임을 사용하고 있습니다 :

-(void)wiggleView { 
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation]; 
    animation.keyPath = @"position.x"; 
    animation.values = @[ @0, @8, @-8, @4, @0 ]; 
    animation.keyTimes = @[ @0, @(1/6.0), @(3/6.0), @(5/6.0), @1 ]; 
    animation.duration = 0.4; 
    animation.additive = YES; 
    [self.layer addAnimation:animation forKey:@"wiggle"]; 
} 
+0

어떻게 이런 애니메이션을 다시 멈출 수 있습니까? –

+0

@ meaning-matter use [view.layer removeAllAnimations]; –