iphone - 围绕缩放的 CALayer 安装 View 框架

标签 iphone ios cocoa-touch core-animation calayer

在下面的方法中,我只是使用 CATransform3DMakeScale 扩大了一堆 CAShapeLayers,它们附加到我的 View 层属性。我能够正确地放大形状层,但是我很难让 View 框架像它应该的那样放大并适合形状层产生的图形。一切都是相同的大小,即 View 框架与所有形状层的大小相同。

有人对如何解决这个问题有任何建议吗?我试过改变 View 转换属性以及 View 层转换属性。不确定我在这里遗漏了什么。

- (void) setSize:(CGSize)size
{
    CATransform3D transform = CATransform3DMakeScale(size.width / (self.graphic.initialSize.width), size.height / (self.graphic.initialSize.height), 1);
    self.layer.sublayerTransform = transform;
    self.frame = CGRectMake(0, 0, size.width, size.height);
    self.graphic.size = CGSizeMake(size.width, size.height);
}

另外供引用,这里是我如何设置 View 层:

- (id)initWithGraphic:(Graphic*)graphic
{
    self = [super initWithFrame:CGRectZero];
    if (self) 
    {
        self.backgroundColor = [UIColor clearColor];

        _graphic = [graphic retain];

        self.frame = CGRectMake(0,0, _graphic.initialSize.width, _graphic.initialSize.height);
        self.layer.shouldRasterize = YES;

        for (int i = 0; i < [_graphic.shapeLayers count]; i++)
        {
            [self.layer addSublayer:[_graphic.shapeLayers objectAtIndex:i]];
        }
    }
    return self;
}

下面是我如何设置其中一个形状图层:

CAShapeLayer *outlineShapeLayer = [[CAShapeLayer alloc] init];
outlineShapeLayer.anchorPoint = CGPointMake(0, 0);
outlineShapeLayer.fillColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor;
outlineShapeLayer.bounds = shapeLayerFrame;
outlineShapeLayer.mutablePath = mutablePath;

最佳答案

我必须这样做,这样我的 View 层也有它的 anchor 和位置设置以匹配我的 CAShapeLayers 然后它起作用了:

self.layer.anchorPoint = CGPointMake(0, 0);
self.layer.position = CGPointMake(0, 0);

关于iphone - 围绕缩放的 CALayer 安装 View 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13941596/

相关文章:

iphone - 在 iOS 上从后台线程向主线程发送消息

iphone - 我们可以使用 SLComposeViewController 在 FB 上共享视频吗?

ios - 如何将委托(delegate)更改为 NSURLSession

ios - 快速将图像转换为二进制

iphone - 使用 ActionScript 3 的触摸事件与鼠标单击事件

ios - Xcode 4.6 自动授权不工作 - "no valid aps-environment"

ios - 是否可以通过 Lightning 数字 AV 适配器使用 Xcode 进行调试?

ios - 无法在由自定义 UIViewController 控制的 UILabel 上设置文本

ios - 检查 intValue 时文本字段中的标点符号导致错误行为

objective-c - 关于 Google 文档文档更新的推送通知