我正在开发一个 iPhone 应用程序,我需要在动画中缓慢向上移动第一个视图控制器并移动到第二个视图控制器。我正在考虑使用 CoreAnimation 将第一个视图控制器缓慢向上移动并推送到下一个视图控制器。有人可以帮助提供可用于实现此目的的类/api吗?
谢谢!
我正在开发一个 iPhone 应用程序,我需要在动画中缓慢向上移动第一个视图控制器并移动到第二个视图控制器。我正在考虑使用 CoreAnimation 将第一个视图控制器缓慢向上移动并推送到下一个视图控制器。有人可以帮助提供可用于实现此目的的类/api吗?
谢谢!
尝试这个,
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:yourfirstview cache:YES];
[UIView setAnimationDidStopSelector:@selector(remove_view)];
//change frame here
yourfirstview.frame =CGRectMake(0,-480,320,480);
[UIView commitAnimations];
-(void)remove_view
{
[yourfirstview removeFromSuperview];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:yoursecondview cache:YES];
//change frame here
yoursecondview.frame =CGRectMake(0,0,320,480);
[UIView commitAnimations];
}
You can easily achieve this on a single view controller using multiple UIView
s
As per Apple's documentation:
In iOS 4 and later, use the block-based animation methods.
So, in order to produce the intended results, using the following code.
UIView *mySecondView = [[UIView alloc] initWithFrame:CGRectMake(0, 480, 320, 480)];
[mySecondView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:mySecondView];
[UIView animateWithDuration:2.0 delay:3.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[mySecondView setTransform:CGAffineTransformMakeTranslation(0, -480)];
}completion:^(BOOL done){
}];