gpt4 book ai didi

ios - 在 CALayer 中定位内容

转载 作者:行者123 更新时间:2023-11-29 11:03:45 27 4
gpt4 key购买 nike

如何在 CALayer 中定位内容,使其缩放以适应宽度(保持纵横比)并定位在层的顶部?

更具体地说,我正在尝试使用 AVCaptureVideoPreviewLayer 实现此定位。如果我将预览层的 videoGravity 设置为 AVLayerVideoGravityResizeAspectFill,那么它将填充宽度但将内容垂直居中在框架中(切断顶部和底部)。

最佳答案

尝试使用 .contentGravity 属性 -

A constant that specifies how the layer's contents are positioned or scaled within its bounds

<CALayer>.contentsGravity = kCAGravityResizeAspect;

可能

CA_EXTERN NSString * const kCAGravityCenter
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityTop
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityBottom
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityLeft
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityRight
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityTopLeft
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityTopRight
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityBottomLeft
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityBottomRight
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityResize
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityResizeAspect
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityResizeAspectFill
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);

关于ios - 在 CALayer 中定位内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14615464/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com