애니메이션을 적용해야하는보기가 4 가지입니다. 사용자가 버튼을 누르면 애니메이션에 view1
이 1 초 동안 숨겨져 있고 view2
,이어서 view3
, view4
입니다.서로 다른 뷰에 애니메이션을 순차적으로 적용하는 방법은 무엇입니까?
문제는 시퀀스가있는 다른 뷰에서 애니메이션을 적용하는 방법입니다.
코어 애니메이션을 사용해야합니다.
애니메이션을 적용해야하는보기가 4 가지입니다. 사용자가 버튼을 누르면 애니메이션에 view1
이 1 초 동안 숨겨져 있고 view2
,이어서 view3
, view4
입니다.서로 다른 뷰에 애니메이션을 순차적으로 적용하는 방법은 무엇입니까?
문제는 시퀀스가있는 다른 뷰에서 애니메이션을 적용하는 방법입니다.
코어 애니메이션을 사용해야합니다.
animateWithDuration:animations:completion:
메서드를 사용합니다. 여기서 완료 블록은 다음 애니메이션을 실행하는 메서드를 호출합니다 (마찬가지로 완료 블록은 체인의 다음 부분을 시작합니다).
중첩 애니메이션을 사용하면 원하는 것을 얻을 수 있습니다.
는
- (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){
}];
}];
}];
}];
}];
}
이 코드를 시도 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];
}
];
}