Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,

I am attempting to draw this plane with Core Animation:

pa1.png


(without the black background, however).

This is the code in my custom NSView:

Code:
- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self A_singlePlane];
    }
    return self;
}

-(void)A_singlePlane{
    CALayer *container = [CALayer layer];
    container.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [self.layer addSublayer:container];
    
    CALayer *purpleLayer = [self addPlaneToLayer:container size:CGSizeMake(100, 100) position:CGPointMake(100, 100) color:[NSColor purpleColor]];
    
    CATransform3D t = CATransform3DIdentity;
    t = CATransform3DRotate(t, 45.0f * M_PI / 180.f, 0, 1, 0);
    purpleLayer.transform = t;
   
}

-(CALayer *)addPlaneToLayer:(CALayer* )container size:(CGSize)size position:(CGPoint)point color:(NSColor *)color{

    CALayer *plane = [CALayer layer];
    
    plane.backgroundColor = [color CGColor];
    plane.opacity = 0.6;
    plane.frame = CGRectMake(point.x, point.y, size.width, size.height);
    plane.borderColor = [[NSColor colorWithWhite:1.0 alpha:0.5] CGColor];
    plane.borderWidth = 3.0;
    plane.cornerRadius = 10.0;
    [container addSublayer:plane];
   
    return plane;
}

I have a view in interface builder with the class set as my custom NSView class. My custom view is set to have a layer. The result is a blank NSWindow. I do not receive any errors or warnings.


Does anyone see where my logical flaw is?

Thanks!
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Time to use the debugger... For example, what is the frame in the initialisation? Does your view actually get added to a superview?

Surely you started with something simple that worked, then added things and checked at every step. What was the last version of the code that worked?
 

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
I ended up fixing it by adding:

Code:
self.wantsLayer = YES;

Apparently the checkbox in Interface Builder for adding a layer is not the same as writing it out in Objective-C?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.