【发布时间】:2013-03-19 18:34:51
【问题描述】:
我正在为包含多个子视图的图层支持视图设置动画。一切都使用自动布局进行布局。目前,当我为视图设置动画时,子视图并未随之缩放:
我希望以最终大小绘制一次整个内容,然后根据动画进行缩放。 layerContentsPlacement 和 layerContentsRedrawPolicy 属性似乎是我正在寻找的,但更改它们似乎没有任何效果。
这是我如何制作动画的基本流程:
// Add itemView to canvas
NSView *itemView = // ...
itemView.layerContentsPlacement = NSViewLayerContentsPlacementScaleProportionallyToFit;
itemView.layerContentsRedrawPolicy = NSViewLayerContentsRedrawBeforeViewResize;
[parentView addSubview:itemView];
// Add constraints for the final itemView frame ...
// Layout at final state
[parentView layoutSubtreeIfNeeded];
// Set initial animation state
itemView.alphaValue = 0.0f;
itemView.frame = // centered zero'ed frame
// Set final animation state
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 0.25f;
context.allowsImplicitAnimation = YES;
itemView.alphaValue = 1.0f;
[parentView layoutSubtreeIfNeeded];
} completionHandler:nil];
【问题讨论】:
-
简短回答:不要将视图大小调整为动画。改为使用变换对其进行缩放。
标签: cocoa animation core-animation autolayout appkit