我如何将 aCALayer
居中UIView
?
我有以下代码,但似乎无法CALayer
在视图中居中。图层的图像似乎总是以屏幕中心的右下角结束。
UIView
代码:
- (void)awakeFromNib {
testLayer = [CALayer layer];
testLayer = [[UIScreen mainScreen] scale];
testLayer = kCAGravityCenter;
testLayer.contents = (id) self.testImage.CGImage;
[testLayer setPosition:self.center];
[self.layer addSublayer:testLayer];
}
- (void)layoutSubviews {
testLayer.frame = self.bounds;
}