我有一个 UIButton。在这个按钮上,我应用了一个 CGAffineTransform
,如下所示:
_mainButton.transform = CGAffineTransformMakeRotation((degrees-heading.trueHeading) * M_PI / 180);
通过这种方式,我可以旋转所有按钮,但我只想旋转背景图像。
因此,myButton.imageView
应该保留在其固定位置。怎么做到的?
最佳答案
您必须像这样旋转 UIButton
的 imageView
属性:
_mainButton.imageView.transform = CGAffineTransformMakeRotation((degrees-heading.trueHeading) * M_PI / 180);
ImageView 按钮的 ImageView 。 (只读)
@property(nonatomic, readonly, retain) UIImageView *imageView
讨论
虽然这个属性是只读的,但是它自己的属性是可读/可写的。使用这些属性来配置按钮 View 的外观和行为。例如:
UIButton *button = [UIButton buttonWithType: UIButtonTypeSystem];
button.imageView.exclusiveTouch = YES;
即使按钮尚未显示,imageView 属性也会返回一个值。系统按钮的属性值为 nil。
直接来自Apple的文档
关于ios - CGAffineTransform 旋转 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24109979/