以编程方式旋转 UIScrollView 内容

Rotate programmatically UIScrollView content

我有一个带有 UIImageView 作为子视图的 ScrollView(适合边距)。

ImageView 有一个图像和一些按钮作为子视图。

我需要同时旋转图像和按钮(而不是在设备旋转时)。

现在,旋转图像非常容易:

image = [[UIImage alloc] initWithCGImage: image.CGImage scale: 1.0 orientation: UIImageOrientationLeft];

还旋转按钮可能很无聊,所以我想知道是否有一种方法可以旋转整个 UIScrollView 内容。

查看UIView的transform属性。如果我没理解错的话,它可以完成这项工作。例如: scrollView.transform = CGAffineTransformMakeRotation(M_PI_2);

使用Swift 4:

scrollView.transform = CGAffineTransform(rotationAngle: .pi / 2)