swift - 为什么 Swift Playgrounds 不显示 View 的转换?

标签 swift rotation cgaffinetransform swift-playground

例如,这段代码只是在 Playground 中显示了一个未旋转的矩形

let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 150))
view.backgroundColor = UIColor.blue
view.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI / 3))

enter image description here

什么时候应该是这样的:

enter image description here

最佳答案

Playground 为您提供 View 的预览,而不是在另一个 View 中渲染它。 transform 属性仅影响 View 的表示层,而不影响其实际边界。如果您想查看转换,请将转换后的 View 添加到 playgrounds 实时 View 中,然后在右侧的辅助编辑器中查看。

import PlaygroundSupport
import UIKit
let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 150))
view.backgroundColor = UIColor.blue
view.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI / 3))
let rootView = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
rootView.addSubview(view)
PlaygroundPage.current.liveView = rootView

关于swift - 为什么 Swift Playgrounds 不显示 View 的转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41454687/

相关文章:

swift - 两个 NSDate 的计算差异是错误的 - 已修复

ios - 在应用程序委托(delegate)中导入 AWSCore header - Swift

ios - 如何将 UIView 旋转固定的 +/- 角度?

ios - 如何在 Objective-C 中同时防止对象上的 2 个动画?

ios - 动画增大/减小尺寸 imageView iOS

ios - 有人可以帮我删除表格 View 单元格吗?

ios - 整数文字 '115000159351' 存储到 'Int' 时会溢出,但在一个项目中工作正常,但在另一个项目中则不然 - Swift

javascript - 在 JavaScript 中旋转数组中的元素

ios - 旋转 UIView 导致它改变位置

ios - 缩放/动画UIView的一侧变小? -CGAffineTransformMakeScale