我目前使用這個核心動畫; (iOS 5中,ARC)CoreAnimation:將動畫對象轉移到下一個UIViewController
- (void)onTimer
{
// build a view from our image
UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
// use the random() function to randomize up our flake attributes
int startX = round(random() % 320);
int endX = startX; //round(random() % 320);
double scale = 1/round(random() % 100) + 1.0;
double speed = 1/round(random() % 100) + 1.0;
// set the flake start position
flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
flakeView.alpha = 0.8;
// put the flake in our main view
[self.view addSubview:flakeView];
[self.view sendSubviewToBack:flakeView];
[UIView beginAnimations:nil context:(__bridge void*)flakeView];
// set up how fast the flake will fall
[UIView setAnimationDuration:10 * speed];
// set the postion where flake will move to
flakeView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 25.0 * scale);
// set a stop callback so we can cleanup the flake when it reaches the
// end of its animation
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
UIImageView *flakeView = (__bridge UIImageView*)context;
[flakeView removeFromSuperview];
flakeView = nil;
}
火;
[NSTimer scheduledTimerWithTimeInterval:(0.3) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
有了這段代碼,就有10個雪片被呈現,掉下來。
藉助此代碼以及一些自定義視圖轉換,我正在嘗試使導航操作變得流暢。問題是我無法找到正確的方法將這些(動畫)上下文轉移到下一個UIViewController
,所以所有的動畫片雪花將繼續保持他們離開的位置,並且下一個UIViewController
的NSTimer
將激發新的動畫。
任何幫助和建議將appriciated。
您不清楚您嘗試傳輸的內容。你想把實際的圖像視圖轉移到下一個控制器嗎?描述你正在尋找的視覺效果可能很有用。順便說一句,你根本不應該使用這種動畫方法。您應該在iOS 4或更高版本中使用基於塊的方法。 – rdelmar 2013-03-16 04:58:07