Thanks for the responses.

The problem is still there.

I don’t need to dynamically add or remove views and was following the wrong way 
to setup view hierarchy in drawRect:.

I have changed it to the following order: initWithFrame: then 
-(void)setupSubViews in all related classes.
So in app delegate I call initWithFrame: and then immediately setupSubViews. 
The entire view comes to front a lot later.

The view hierarchy is complex, starting with a view based outline view, then 
child of a root node has box views (2 in a row). Every box has this bottom view 
which has this problem. I’m adding a non-selectable, non-editable text field 
with setDrawsBackground set to NO, as a subview to this bottom view.

In drawRect:, I’m just using NSRectFill() with:

NSColor *bgColor = [[NSColor blackColor]blendedColorWithFraction:0.25 
ofColor:[NSColor whiteColor]];
    [bgColor set];
    NSRectFill([self bounds]);
And initially the background is same in text field and rest of the area. but on 
refresh, the rest of the area becomes darker, which shouldn’t be as 
NSRectFill() is supposed to draw opaquely.


Thanks,
Navneet


> On 30-Nov-2014, at 11:24 pm, Kyle Sluder <k...@ksluder.com> wrote:
> 
> On Nov 30, 2014, at 9:30 AM, Navneet Kumar <navnee...@me.com> wrote:
>> 
>> Hi,
>> 
>> I have a custom view in which I am setting the background using NSRectFill() 
>> in drawRect:.
> 
> You’re aware that this function is only really suitable for drawing opaque 
> colors, yes? If you NSRectFill() with a transparent color, it will not blend 
> that color with the existing backing store. Instead, it will replace all 
> pixels in that rect with transparent ones, obliterating any drawing performed 
> by ancestor views in the hierarchy.
> 
>> I am also adding a text field as subview in this method.
> 
> This is not allowed. -drawRect: is for drawing, not mutating your view 
> hierarchy.
> 
> If you want to position/install views at the last possible second before the 
> drawing pass, use -viewWillDraw. But you have not offered any reasons why you 
> need to dynamically add or remove views at all, much less in tandem with the 
> drawing pass.
> 
> --Kyle Sluder

_______________________________________________

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