我已经使用 CABasicAnimation 为我的菜单创建了动画。以下是我与此问题相关的代码:
- (void) viewDidLoad {
...
[self setAwesomeMenu];
}
- (void)setAwesomeMenu {
...
//set tag for awesomemenu subview
[menu setTag:awesomeMenuSubViewTag];
[self addPulseFilterSubView];
}
- (void) addPulseFilterSubView {
// add pulseEffectFilter subview
UIImageView *pulseEffectFilter = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pulse.png"]];
[self.view insertSubview:pulseEffectFilter belowSubview:[self.view viewWithTag:awesomeMenuSubViewTag]];
pulseEffectFilter.center = CGPointMake(160.0, 205.0);
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
theAnimation.duration=2.0;
theAnimation.repeatCount=HUGE_VALL;
//theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:0.0];
theAnimation.toValue=[NSNumber numberWithFloat:1.3];
[pulseEffectFilter.layer addAnimation:theAnimation forKey:@"transform.scale"];
theAnimation.removedOnCompletion = NO; // doesn't help
CABasicAnimation *fadeOutAnimation;
fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeOutAnimation.fromValue = [NSNumber numberWithFloat:1.2];
fadeOutAnimation.toValue = [NSNumber numberWithFloat:0.0];
fadeOutAnimation.duration = 1.0;
fadeOutAnimation.repeatCount=HUGE_VALL;
[pulseEffectFilter.layer addAnimation:fadeOutAnimation forKey:@"opacity"];
//fadeOutAnimation.autoreverses = YES;
fadeOutAnimation.removedOnCompletion = NO; //doesn't help
[pulseEffectFilter setTag:pulseEffectFilterSubViewTag];
}
当我第一次调用这个 View 时,动画效果很好。当这个应用程序从电话暂停中重新出现时,动画也可以正常工作。 但是当我切换到另一个应用程序或换句话说离开这个应用程序,然后重新进入这个应用程序时,动画被卡住了。我找到了一个 article谈论这个。他们声称可以通过在 CABasicAnimation 类上将名为 removedOnCompletion 的标志设置为 NO 来解决这个问题。不幸的是,在我的情况下它不起作用。有谁知道解决方案吗?提前致谢。
最佳答案
好的,我已经测试了您的代码并找到了修复方法。在您的应用委托(delegate)中添加以下内容:
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[NSNotificationCenter defaultCenter] postNotificationName:@"resumeAnimation" object:nil];
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
然后添加一个 bool 来跟踪动画是否打开并注册通知(在您的 View 类中):
BOOL animationActive = NO;
@interface ViewController ()
@end
@implementation ViewController
- (void) viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addPulseFilterSubView) name:@"resumeAnimation" object:nil];
[self setAwesomeMenu];
}
然后在 addPulseFilterSubView 开始时检查我们是否需要停止之前的动画:
- (void) addPulseFilterSubView {
if (animationActive) {
for (UIView * view in self.view.subviews) {
if (view.tag ==pulseEffectFilterSubViewTag) {
[view removeFromSuperview];
}
}
}
// add pulseEffectFilter subview
UIImageView *pulseEffectFilter = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pulse.png"]];
[self.view insertSubview:pulseEffectFilter belowSubview:[self.view viewWithTag:awesomeMenuSubViewTag]];
...
然后在这个方法的最后:
animationActive = YES;
}
一切都应该很好 :D
关于ios - Core Animation 在应用重新出现时停止动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28110606/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的