title: NSView CALayer Opacity Madness
body: <p>It seems as though the layer's properties of my NSView are sometimes not editable/wrong. In the code below, the animation works perfectly, and all appears normal. The output from the NSlogs are always : </p>
  
  <pre><code>anim over opacity = 1.00000
  first opacity = 0.50000
  current opacity = 0.00000
  updated opacity = 0.00000
  </code></pre>
  
  <p>The first two logs look right, so even at animation did stop, the layer seems to operate normally. However, some time later, when I check the opacity it magically turned to 0. Further wrong, when I set the layer's opacity to 1, and check it immediately after, it still is 0. How is that possible?</p>
  
  <p>I goofed around with setneedsdisplay in the layer and setneedsdisplay:YES in nsview and that
  didn't help. Any suggestions are greatly appreciated.</p>
  
  <pre><code>- (void) someSetupAnimationMethod {
          aLayer = [CALayer layer];
          [theView setWantsLayer:YES];
          [theView setLayer:aLayer];
  
          [aLayer setOpacity:0.0];
          CABasicAnimation *opacity = [CABasicAnimation animationWithKeyPath:@"opacity"];
          opacity.byValue = [NSNumber numberWithFloat:1.0];
          opacity.duration = 0.3;
          opacity.delegate = self;
          opacity.fillMode = kCAFillModeForwards;
          opacity.removedOnCompletion = NO;
          [opacity setValue:@"opacity done" forKey:@"animation"];
          [aLayer addAnimation:opacity forKey:nil];
      }
  
      - (void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
          if([[anim valueForKey:@"animation"] isEqualToString:@"opacity done"]) {
             NSLog(@"anim over opacity = %f", aLayer.opacity);
             aLayer.opacity = 0.5;
             [aLyaer removeAllAnimations];
             NSLog(@"first opacity = %f", aLayer.opacity);
          }
      }
  
      - (void) someLaterMethod {
          NSLog(@"current opacity = %f", aLayer.opacity);
          aLayer.opacity = 1.0;
          NSLog(@"updated opacity = %f", aLayer.opacity);
      }
  </code></pre>