【发布时间】:2011-09-29 22:10:08
【问题描述】:
我有 2 个占据整个屏幕的子视图(状态栏除外)。我们称这个尺寸为“屏幕尺寸”。
我想同时动画:
第一个从比屏幕尺寸大一点的屏幕尺寸缩放到屏幕尺寸,从 alpha 0 到 alpha 1。
秒从屏幕尺寸到比屏幕尺寸小一点,从alpha 1到alpha 0。
第二个视图在开始时可见并在屏幕上。
这是我写的:
- (void) switchViews
{
if (self.view2Controller == nil) {
self.view2Controller = [[View2Controller alloc] initWithNibName:@"View2XIB" bundle:nil];
self.view2Controller.view.hidden = YES;
[self.view addSubview:self.view2Controller.view];
}
CGRect bigFrame = CGRectInset(self.view.frame, -50, -50);
CGRect normalFrame = self.view.frame;
CGRect smallFrame = CGRectInset(self.view.frame, 50, 50);
self.view2Controller.view.frame = bigFrame;
self.view2Controller.view.alpha = 0.0;
[UIView beginAnimations:@"Anim1" context:nil];
[UIView setAnimationDuration:5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
self.view2Controller.view.hidden = NO;
self.view2Controller.view.frame = normalFrame;
self.view2Controller.view.alpha = 1.0;
[UIView commitAnimations];
// ------------------------------
[UIView beginAnimations:@"Anim2" context:nil];
[UIView setAnimationDuration:5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
self.view1Controller.view.frame = smallFrame;
self.view1Controller.view.alpha = 0.0;
[UIView commitAnimations];
}
当然,我首先尝试将两个动画都放入一个独特的动画中。这不会改变任何事情,这就是我试图将它们分开的原因。
启动时,view1 立即变为黑色,然后 view2 开始按预期设置动画。但我无法同时运行两个动画。
我该怎么做?
【问题讨论】:
标签: iphone ios cocoa-touch animation uiview