当我绘制这个对象时,它会工作一次,但之后我的路径对象(女巫是NSBezierPath)会在NSCFTimer对象中发生变化。
- (void)draw {
NSRect drawingbounds = [self drawingbounds];
if(image == nil) {
image = [[NSImage alloc] initWithSize:drawingbounds.size];
[image lockFocus];
NSAffineTransform *transform = [NSAffineTransform transform];
[transform translateXBy:-drawingbounds.origin.x yBy:-drawingbounds.origin.y];
[transform concat];
[[NSColor redColor] set];
[path stroke];
[image unlockFocus];
[image retain];
}
[image drawAtPoint:NSMakePoint(10.0, 10.0)
fromRect: NSMakeRect(0.0, 0.0, 100.0, 100.0)
operation: NSCompositeSourceOver
fraction: 1.0];
}
- (NSRect)drawingbounds {
NSLog([path description]);
return NSMakeRect(10.0, 10.0, 100.0, 100.0);
return NSInsetRect([path bounds], -[path lineWidth] , -[path lineWidth]);
}
答案 0 :(得分:1)
请发布创建path
变量的代码。
听起来路径对象正在被解除分配,这就是为什么你在其内存位置看到另一个对象(NSCFTimer
)的原因。如果您没有正确保留path
对象,就会发生这种情况。