Core Animation -- Nothing Appears

Discussion in 'Mac Programming' started by Blakeasd, Feb 15, 2014.

  1. Blakeasd macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    Hello,

    I am attempting to draw this plane with Core Animation:

    [​IMG]

    (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!
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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?
     
  3. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #3
    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?
     

Share This Page