|
From: | Lundberg, Johannes |
Subject: | Re: Redraw view in setFrame? |
Date: | Thu, 31 Oct 2013 15:30:54 +0900 |
Hi,
Am 31.10.2013 um 03:07 schrieb Lundberg, Johannes:
https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/setFrame:
> Hi All!
>
> I've been playing with the NSViewAnimation class and discovered that the view is not redrawn between animation steps.
>
> First I was thinking that a call could be made to [_target setNeedsDisplay] at each animation step in NSViewAnimation.m but wouldn't it be better to do that in NSView's setFrame?
"It neither redisplays the receiver nor marks it as needing display. You must do this yourself with display or setNeedsDisplay:."
Not necessarily. A view may be hidden. Or resized several times. Well, a setNeedsDisplay:YES wouldn't do any harm - an invisible view isn't drawn even if set to needsDisplay... But it costs calculation time (especially for rotated and scaled views).
>
> Whenever you change the frame of a view don't you want it to always redraw anyway?
It may be done but you should never rely on it in your code.
>
> This seems to be the case on Cocoa. I've attached a Xcode 5 project example app that shows that view is redrawn without calling setNeedsDisplay when changing frame. (not sure if the same applies to Cocoa Touch though...)
[[self superview] setNeedsDisplayInRect:oldFrame] would be more correct IMHO.
>
> Another thing is that when moving or shrinking a view setNeedsDisplay needs to be called before and after the new frame is set otherwise the area of the old frame view won't be cleared.
>
> Have this kind of code in your app is not so elegant.
>
> [view setNeedsDisplay:YES];
> view.frame = newFrame;
> [view setNeedsDisplay:YES];
>
> I propose that we move that into NSView. I made a dirty fix that may not be the optimal way to do it but it shows what I want to do with this proposal.
>
>
> in NSView's - (void) setFrame: (NSRect)frameRect i added two calls to setNeedsDisplay like this:
>
> if (changedSize == YES || changedOrigin == YES)
> {
> [self setNeedsDisplay:YES];
IMHO it could be done, just in case that some application is not doing it correctly. But this may help programmers to do it not correctly and writing wrong code which makes porting to other *STEP platforms fail.
> [self _setFrameAndClearAutoresizingError: frameRect];
> [self setNeedsDisplay:YES];
> ......
>
> What do you guys think?
Just my 2ct.
-- hns
[Prev in Thread] | Current Thread | [Next in Thread] |