我有2個子視圖需要整個屏幕(除了狀態欄)。我們稱這個尺寸爲「屏幕尺寸」。iPhone - 同時動畫2個子視圖
欲動畫兩者:
從一點點比屏幕尺寸與屏幕尺寸較大,以放大所述第一,從阿爾法0到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按預期開始動畫。但我無法同時運行兩個動畫。
我該怎麼做?
呃......你在開玩笑嗎?我會盡量隔離你今晚做的代碼。 :-) – Oliver
啊啊......對不起,但是不......你的搜索字段比你發送的代碼大一點......試試我隔離的代碼(查看新的編輯答案) – meronix