- (ID<CAAction>)actionForKey:(Nsstring *)key { // Custom animations return [super actionForKey:key];}
然后我可以创建一个动画并将其返回给onorderIn动作(即将图层添加到另一个图层时).这很好用.如果我对onorderOut执行相同的 *** 作(即从超级图层中删除图层),则会忽略返回的动画,而是应用默认动画.
我的目标是缩放(onorderIn)和out(onorderOut)中的图层:
- (ID<CAAction>)actionForKey:(Nsstring *)key { if ([key isEqualToString:@"onorderIn"] || [key isEqualToString:@"onorderOut"]) { CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; a.duration = 0.25; a.removedOnCompletion = NO; a.fillMode = kCAFillModeBoth; if ([key isEqualToString:@"onorderIn"]) { a.fromValue = [NSNumber numberWithfloat:0.0]; a.tovalue = [NSNumber numberWithfloat:1.0]; } else { a.fromValue = [NSNumber numberWithfloat:1.0]; a.tovalue = [NSNumber numberWithfloat:0.0]; } return a; } return [super actionForKey:key];}
放大作品,缩小不会.而是使用默认的淡出动画.
代码可能包含一些拼写错误,因为我在另一台机器上输入了这个.
有人可以帮忙吗?
解决方法 在 quartz-dev mailing list引用约翰哈珀:There’s a fundamental problem with
returning any animation for the
onorderOut key—by the time the
animation should be running,the layer
is no longer in the tree,so it has no
effect. So onorderOut is not useful
for triggering animations; it may be
useful for running other code when
layers are removed from the tree.The best solution I’ve found for this
(assuming the default fade Transition
on the parent is not what you want,
which it often isn’t) is to add custom
animations to apply the removal effect
you want,then,in the dIDStop
animation delegate,actually remove
the layer. It’s often convenIEnt to
create a single group of animations
with the delegate property set,and
fillMode=forwards,
removedOnCompletion=NO so that you can
remove the layer at the end of the
animation with no possibility of the
layer still being visible in its
normal state.
如果您做了很多这样的事情,很容易编写一个启动动画的公共超类,将动画委托设置为类并实现animationDIDStop:删除未启用动画的图层.这恢复了您希望在默认实现中出现的CoreAnimation的“即发即忘”特性.
总结以上是内存溢出为你收集整理的objective-c – 如何在Core Animation中为onOrderOut使用自定义动画?全部内容,希望文章能够帮你解决objective-c – 如何在Core Animation中为onOrderOut使用自定义动画?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)