アニメーションを適用する必要がある 4 つのビューがあります。ユーザーがボタンをタップすると、アニメーションはview1
1 秒間非表示になりview2
、次に 、次にview3
になりview4
ます。
問題は、シーケンスを使用して異なるビューにアニメーションを適用する方法です。
Core Animation を使用して仕上げる必要があります。
アニメーションを適用する必要がある 4 つのビューがあります。ユーザーがボタンをタップすると、アニメーションはview1
1 秒間非表示になりview2
、次に 、次にview3
になりview4
ます。
問題は、シーケンスを使用して異なるビューにアニメーションを適用する方法です。
Core Animation を使用して仕上げる必要があります。
このコードを試して、
h.
NSInteger currentView;
UIView *view1, *view2, *view3, *view4;
メートル。
-(void)viewDidLoad {
[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];
}
-(IBAction)buttonPressed:(id)送信者 {
[self runAnimation];
}
-(UIView *)viewForAnimation:(NSInteger)index {
switch (index)
{
case 1:
return view1;
case 2:
return view2;
case 3:
return view3;
case 4:
return view4;
}
return view1;
}
-(void)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];
}
];
}