我希望整个事物能够以最终尺寸绘制,然后按照动画进行缩放. layerContentsPlacement和layerContentsRedrawPolicy属性似乎是我正在寻找的,但更改它们似乎没有任何影响.
这是我如何进行动画的基本演练:
// Add itemVIEw to canvasNSVIEw *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 stateitemVIEw.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];解决方法 感谢大卫的评论,我转而使用视图层的变换.
基本思想是像往常一样创建和布局视图,然后创建一些CA动画并将其添加到视图的图层.
// Add item vIEw to canvasNSVIEw *itemVIEw = // ...[parentVIEw addSubvIEw:itemVIEw];// Add constraints for the final item vIEw positioning// Layout at final state[parentVIEw layoutSubtreeIfNeeded];// AnimateCABasicAnimation *animation = [CABasicAnimation animation];CAtransform3D transform = CAtransform3DMakeScale(0.5f,0.5f,0.5f);animation.fromValue = [NSValue valueWithCAtransform3D:transform];animation.duration = 1.0f;[itemVIEw.layer addAnimation:animation forKey:@"transform"];// create any other animations...总结
以上是内存溢出为你收集整理的cocoa – 为图层支持的视图设置动画时缩放图层内容全部内容,希望文章能够帮你解决cocoa – 为图层支持的视图设置动画时缩放图层内容所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)