2013-08-06 5 views

답변

2

animateWithDuration:animations:completion: 메서드를 사용합니다. 여기서 완료 블록은 다음 애니메이션을 실행하는 메서드를 호출합니다 (마찬가지로 완료 블록은 체인의 다음 부분을 시작합니다).

0

중첩 애니메이션을 사용하면 원하는 것을 얻을 수 있습니다.

- (IBAction)yoiurButtonClickAction:(id)sender{ 
    [UIView animateWithDuration:1.0 
          delay: 0.0 
         options:UIViewAnimationOptionCurveEaseOut 
        animations:^{ 
         _view1.alpha = 0.0; 
        } 
        completion:^(BOOL finished){ 
         [UIView animateWithDuration:1.0 
               delay: 0.0 
              options:UIViewAnimationOptionCurveEaseInOut 
              animations:^{ 
               _view1.alpha = 1.0; 
               _view2.alpha = 0.0; 
              } 
              completion:^(BOOL finished){ 
               [UIView animateWithDuration:1.0 
                    delay: 0.0 
                    options:UIViewAnimationOptionCurveEaseInOut 
                   animations:^{ 
                    _view2.alpha = 1.0; 
                    _view3.alpha = 0.0; 
                   } 
                   completion:^(BOOL finished){ 
                    [UIView animateWithDuration:1.0 
                         delay: 0.0 
                         options:UIViewAnimationOptionCurveEaseInOut 
                        animations:^{ 
                         _view3.alpha = 1.0; 
                         _view4.alpha = 0.0; 
                        } 
                        completion:^(BOOL finished){ 
                         [UIView animateWithDuration:1.0 
                               delay: 0.0 
                              options:UIViewAnimationOptionCurveEaseInOut 
                             animations:^{ 
                              _view4.alpha = 1.0; 

                             } 
                             completion:^(BOOL finished){ 

                             }]; 
                        }]; 
                   }]; 
              }]; 
        }]; 
} 
0

이 코드를 시도 Animations in UIView,

시간을 참조하십시오.

NSInteger currentView; 
UIView *view1, *view2, *view3, *view4; 

m.

- (공극)이 {

[super viewDidLoad]; 

currentView = 1; 

view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 100)]; 
[view1 setBackgroundColor:[UIColor redColor]]; 
[self.view addSubview:view1]; 

view2 = [[UIView alloc]initWithFrame:CGRectMake(80, 0, 80, 100)]; 
[view2 setBackgroundColor:[UIColor blueColor]]; 
[self.view addSubview:view2]; 

view3 = [[UIView alloc]initWithFrame:CGRectMake(160, 0, 80, 100)]; 
[view3 setBackgroundColor:[UIColor greenColor]]; 
[self.view addSubview:view3]; 

view4 = [[UIView alloc]initWithFrame:CGRectMake(240, 0, 80, 100)]; 
[view4 setBackgroundColor:[UIColor yellowColor]]; 
[self.view addSubview:view4]; 

}

의 viewDidLoad - (IBAction를)의 buttonPressed를 (ID) 송신기 {

[self runAnimation];  

}

- (UIView의 *) viewForAnimation : (NSInteger) 인덱스 {

switch (index) 
{ 
    case 1: 
     return view1; 
    case 2: 
     return view2; 
    case 3: 
     return view3; 
    case 4: 
     return view4; 
} 
return view1; 

}

- (공극) runAnimation {

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveLinear 
       animations:^ 
{ 
    [self viewForAnimation:currentView].hidden = YES; 
} 
       completion:^(BOOL finished) 
{ 
    currentView++; 
    if(currentView < 5) 
     [self performSelector:@selector(runAnimation) withObject:nil afterDelay:1.5]; 
} 
]; 

}

관련 문제