On 24/03/2012, at 9:30 PM, Jonathan Guy wrote:

> Hi all
> This is must be the most simple a puzzling problem I've had. Take a new app, 
> create a custom view class with a drawrect of
> 
> - (void)drawRect:(NSRect)dirtyRect
> {
>    if ([NSApp isActive]) {
>               [[NSColor redColor] set];
>       }
>       else {
>               [[NSColor blueColor] set];
>       }
>       NSRectFill([self bounds]);
> }
> 
> pretty simple stuff you would think but if I drop this custom view onto the 
> main window and run it up the view draw a blue square??? how bizarre. If I 
> resize the window it suddenly draws red but deactivating a reactivating the 
> app is not redrawing the view with the correct color. What is going on here? 
> I can only think the whole view is being clipped as the system doesn't think 
> it needs to be redrawn as the very first drawrect the app is showing as 
> inactive but then subsequently drawrect  gets called again with the app in an 
> active state so it initially draws blue but then is supposed to draw red but 
> that's not happening.
>       Any help would be appreciated.
> Thanks


The problem is, I think, that the view is not automatically invalidated when 
the app is inactivated or activated. Therefore what you see is whatever it was 
in its previous state. You need to listen for the activation/inactivation 
notification, and invalidate the view.

--Graham




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to