【发布时间】:2013-03-16 00:48:26
【问题描述】:
我目前正在使用这个核心动画; (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 将触发新的那些。
任何帮助和建议都将得到应用。
【问题讨论】:
-
不清楚您要转移什么。您是否希望将实际的图像视图传输到下一个控制器?描述您正在寻找的视觉效果可能很有用。顺便说一句,您根本不应该使用这种动画方法。您应该在 iOS 4 或更高版本中使用基于块的方法。
标签: iphone ios objective-c core-animation