CALayer内存分配问题

时间:2013-11-25 14:00:55

标签: ios objective-c core-graphics calayer

我的iPad应用程序显示出一些奇怪的行为。有一些使用Core Graphics的自定义UIView,我发现当删除视图并调用dealloc时,'CALayer'的内存保持活动状态?我使用抽屉式应用程序,因此每次显示视图时,内存使用量基本上翻倍。这就是我在仪器中得到的,任何人都知道为什么会发生这种情况?

Instruments output

VDCircuitHeadingIndicatorView的LayoutSubviews

- (void)layoutSubviews
{
    // Super
    [super layoutSubviews];

    // Create arrow path and set label frames according to arrow direction
    if (self.arrowDirection == VDCircuitHeadingIndicatorArrowDirectionLeft) {
        self.arrow = [UIBezierPath bezierPathWithArrowFromPoint:
            CGPointMake(self.bounds.size.width - (self.lineWidth * 2), self.bounds.size.height / 2) 
            toPoint:CGPointMake((self.lineWidth * 2), self.bounds.size.height / 2)  
            tailWidth:self.bounds.size.height / 1.75 headWidth:self.bounds.size.height - (self.lineWidth * 2) 
            headLength:ARROW_HEAD_LENGTH
        ];

        [self.headingLabel setFrame:
            CGRectMake(ARROW_HEAD_LENGTH * 1.05, (self.bounds.size.height - (self.bounds.size.height / 1.75)) / 2, 
            self.bounds.size.width - (ARROW_HEAD_LENGTH * 1.75), (self.bounds.size.height / 1.75))
        ];

    } else {

        self.arrow = [UIBezierPath bezierPathWithArrowFromPoint:
            CGPointMake((self.lineWidth * 2), self.bounds.size.height / 2) 
            toPoint:CGPointMake(self.bounds.size.width - (self.lineWidth * 2), self.bounds.size.height / 2) 
            tailWidth:self.bounds.size.height / 1.75 
            headWidth:self.bounds.size.height - (self.lineWidth * 2) 
            headLength:ARROW_HEAD_LENGTH
        ];

        [self.headingLabel setFrame:
            CGRectMake(ARROW_HEAD_LENGTH / 1.5, (self.frame.size.height - (self.frame.size.height / 1.75)) / 2, 
            self.frame.size.width - (ARROW_HEAD_LENGTH * 1.75), (self.frame.size.height / 1.75))];

    }

    [self.headingLabel setFont:[UIFont boldSystemFontOfSize:(self.bounds.size.height / 2)]];

    // Rotate view to rotation degrees value
    self.transform = CGAffineTransformMakeRotation(DegreesToRadians(self.rotation));

   // If we have rotated
   if (self.rotation != 0 && [self.superview isKindOfClass:[VDCircuitView class]])
   {
       // Get the x coord and the width of the superview
       float x = self.frame.origin.x;
       float superWidth = self.superview.frame.size.width;

       // If the view's x coord is less than half the width of the superview - set x to 0
       if (x < (superWidth / 2)) {
            self.frame = CGRectMake(0, self.frame.origin.y, self.frame.size.width, self.frame.size.height);
       } else {
            self.frame = CGRectMake(self.superview.bounds.size.width - self.frame.size.width, self.frame.origin.y, self.frame.size.width, self.frame.size.height);
       }
}

来自VDCircuitHeadingIndicatorView的DrawRect

- (void)drawRect:(CGRect)rect
{
    // Super
    [super drawRect:rect];

    [self.arrow setLineWidth:self.lineWidth];

    // Set arrow path colour
    [self.lineColour setStroke];
    [self.arrowBackgroundColour setFill];

    // Stroke arrow path
    [self.arrow stroke];
    [self.arrow fill];
}

0 个答案:

没有答案