作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
当我的应用退出后台时,动画已停止。这是正常的。但我想从当前状态重新开始我的动画。我该怎么做才能不到处乱拍。
[UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
} completion:nil];
我试着在动画前面放一个固定的框架,但这只会让它卡住。
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
有什么想法吗?
最佳答案
您可以在您的类中为 UIApplicationWillEnterForegroundNotification 添加一个观察者:
- (void)addNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
}
- (void)applicationWillEnterForeground {
[self animate];
}
- (void)animate {
[bg setFrame:CGRectMake(0, 0, 0, 0)];
[UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
} completion:nil];
}
设置动画的开始状态很重要(并且不要忘记移除通知观察者)
关于iphone - iOS,退出后台时重启动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6042472/
我是一名优秀的程序员,十分优秀!