iphone - 核心动画 : Transferring animating objects to next UIViewController

标签 iphone ios objective-c core-animation

我目前正在使用这个核心动画; (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 的正确方法,因此所有动画雪花将继续在它们离开的地方继续移动,以及下一个 UIViewControllerNSTimer 将触发新的。

我们将不胜感激任何帮助和建议。

最佳答案

也许你可以把你的上下文放在这个类的私有(private)扩展中。
喜欢:@property (nonatomic,weak)IBOutlet UIImageView*context;

关于iphone - 核心动画 : Transferring animating objects to next UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15444309/

相关文章:

iphone - 检查当前时间是否在时间 A 和 B 之间

ios - 无法将 View Controller 属性获取到另一个 View Controller

ios - 捏合手势未应用于 UILabel 但应用于 UIView

iPhone 内存问题

IOS:带有半径的 UIImageView 边框白色在 4 个角显示一条奇怪的黑线

iphone - 如何删除/禁用配置文件过期警告

iOS - 解锁后第一个网络请求失败

ios - 单元格按钮的操作

ios - 如何在 IOS 中的两个时间间隔之间播放 youtube 视频

objective-c - 如何在 Objective-c 中获取运行时 block 类型元数据?