我正在应用 aCAAnimation
在屏幕上和屏幕外移动工具栏。
当我触摸超级视图时,会触发以下方法:
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[UIView beginAnimations:kViewerToggleToolbarAnimation context:nil];
if (self.viewerToolbarView.isVisible) {
self.viewerToolbarView.frame = CGRectMake(0, self.frame.size.height, self.viewerToolbarView.frame.size.width, self.viewerToolbarView.frame.size.height);
self.viewerToolbarView.isVisible = NO;
}
else {
self.viewerToolbarView.frame = CGRectMake(0, self.frame.size.height - kUIToolbarHeight, self.viewerToolbarView.frame.size.width, self.viewerToolbarView.frame.size.height);
self.viewerToolbarView.isVisible = YES;
}
[UIView commitAnimations];
}
这又会触发子视图的委托方法:
- (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key {
id<CAAction> animation = nil;
if ([key isEqualToString:kViewerToggleToolbarAnimation]) {
animation = [CABasicAnimation animation];
if (self.isVisible)
((CABasicAnimation*)animation).duration = kViewerToolbarHideAnimationDuration;
else
((CABasicAnimation*)animation).duration = kViewerToolbarShowAnimationDuration;
((CABasicAnimation*)animation).timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
}
else {
animation = [super actionForLayer:layer forKey:key];
}
return animation;
}
常量kViewerToggleToolbarAnimation
和在别处定义为kViewerToolbarHideAnimationDuration
:kViewerToolbarShowAnimationDuration
extern NSString * const kViewerToggleToolbarAnimation;
extern CGFloat const kViewerToolbarShowAnimationDuration;
extern CGFloat const kViewerToolbarHideAnimationDuration;
...
NSString * const kViewerToggleToolbarAnimation = @"kViewerToggleToolbarAnimation";
CGFloat const kViewerToolbarShowAnimationDuration = 2.50f;
CGFloat const kViewerToolbarHideAnimationDuration = 2.75f;
问题是我可以在常量文件中增加这些持续时间值,但是委托方法会忽略这些持续时间并应用它自己明显很短的持续时间(大约 0.5 秒)。
2.5 和 2.75 秒是相当长的时间,否则动画会运行,如果它工作正常的话。
我在触发动画时做错了什么,导致这些持续时间常量被忽略?否则它编译并运行良好,因此它不会抱怨无法找到常量。