我目前正在使用这个核心动画;(iOS 5,ARC)
- (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
触发新的。
任何帮助和建议都将得到应用。