我正在为包含多个子视图的图层支持视图制作动画。一切都使用自动布局进行布局。目前,当我为视图设置动画时,子视图不会随之缩放:
我希望以最终大小将整个事物绘制一次,然后在动画时进行缩放。和属性似乎是我正在寻找的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];