2012-07-04 2 views
3

메인 뷰의 일부 버튼과 컨트롤러가 화면의 오른쪽에서부터 화면에 애니메이션으로 표시하려고합니다. 문제는 그것이 움직이지 않는다는 것입니다. 단지 완성 된 상태로 바로 가게됩니다.animateWithDuration not working

내가 다른 애니메이션의 완료 블록 내부에이 애니메이션을 넣을 경우, 일을 더 이상 만들려면 다음이 하나가 작동

UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
options = [storyBoard instantiateViewControllerWithIdentifier:@"OptionsView"]; 
options.delegate = self;   
[self.view addSubview:options.view]; 
options.view.center = CGPointMake(floor(total_width+options.view.frame.size.width/2)+10, floor(total_height/2)); 

[UIView animateWithDuration:0.5 
         delay:0.0 
        options: UIViewAnimationOptionCurveEaseOut 
       animations:^{ 
        options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2)); 
       } 
       completion:^(BOOL finished){ 
        NSLog(@"Done!"); 
       }]; 

편집,하지만 새로운 하나를

이 내 코드입니다.

UIButton* boton = (UIButton*) sender; 
    [UIView animateWithDuration:5.0 
          delay:0.0 
         options: UIViewAnimationOptionCurveLinear 
        animations:^{ 
         boton.alpha = 0.0; 

         //Jumps directly to 0, animation doesn't work 

        } 
        completion:^(BOOL finished){ 
         [UIView animateWithDuration:0.5 
               delay:0.0 
              options: UIViewAnimationOptionCurveEaseInOut 
              animations:^{ 
               options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2)); 

               //It works now, but it doesn't take 5 seconds to start, it starts right away 

              } 
              completion:^(BOOL finished){ 
               NSLog(@"Done!"); 
              }]; 

        }]; 

답변

3

animateWithDuration:... 호출하기 전에 라인은 직접 당신이 애니메이션하고 같은 값으로 center을 할당합니다. 그것을 제거하거나 초기 center 값을 할당하십시오. 시작과 끝 값이 동일한 애니메이션은 분명히 효과가 없습니다.

+0

나는 너무 처음에는 생각했지만 시작 위치에 '+'가 있고 끝 위치에 '-'가 있습니다. – SomaMan

+0

아, 그 점을 간과했습니다. 아마도 두 표현식 모두 '0'으로 평가 될 것이므로 차이는 없습니다. – omz

+0

아니요, 두 표현식 모두 올바르게 평가됩니다. 처음으로 센터를 지정하면 화면 밖으로 설정됩니다. 두 번째로 예상대로 오른쪽 테두리 왼쪽으로 이동합니다. 그러나 애니메이션이없는 경우 – Odrakir