ios - 从中心变换 UIView

标签 ios swift core-animation

我的应用程序中有一个 UIView,我想为其提供小规模动画。动画应该是有弹性的,因为它应该缩小一点,然后恢复到原始大小。

我发现了以下 Objective-C 代码:

headerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);

现在,我将其添加到我的 Swift 代码中:

profileView.transform = CGAffineTransform.identity.scaledBy(x: 0.9, y: 0.9)

但是,现在发生的情况是, View 以左上角看似作为 anchor 进行变换。不过,我希望中心成为 anchor 。关于我做错了什么有什么想法吗?

最佳答案

不使用单位矩阵, 尝试像这样

view.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)

关于ios - 从中心变换 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56157007/

相关文章:

ios - 在图层上设置初始 AffineTransform,然后对累积变换进行动画处理?

ios - 如何在 CallKit 上显示背景图片

ios - 异步请求未正确更新变量

ios - 访问 cellforrow 之外的 tableview 内容

ios - 如何在 WKWebView 使用 Swift 更改之前获取输入值?

swift - SSAccountStore : Unable to get the local account. 错误 = 错误域 = SSErrorDomain 代码 = 100

ios - 使用 transitionWithView 同时显示和隐藏

objective-c - 如何为导航项目设置动画(闪烁或闪烁之类)

iOS 和 XCode : What is the best way to store connection settings (i. URL)用于 iOS 应用程序?

ios - 删除 CGContextAddPath 之后的路径