我目前正在使用这个核心动画; (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 片雪花,落下。
借助此代码和一些自定义 View 转换,我正在尝试使导航操作流畅。问题是我找不到将这些(动画)上下文传输到下一个 UIViewController
的正确方法,因此所有动画雪花将继续在它们离开的地方继续移动,以及下一个 UIViewController
的 NSTimer
将触发新的。
我们将不胜感激任何帮助和建议。
最佳答案
也许你可以把你的上下文放在这个类的私有(private)扩展中。
喜欢:@property (nonatomic,weak)IBOutlet UIImageView*context;
关于iphone - 核心动画 : Transferring animating objects to next UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15444309/