-setNeedsDisplay: different between Tiger and Leopard

  • I am writing code that moves a control from one place to another. In
    Leopard, this works great:

    [control setNeedsDisplay:YES]; // clean up at old location
    [control setFrame:newFrame]; // move control
    [control setNeedsDisplay:YES]; // redraw at new location

    However, in Tiger, this doesn't work properly; the control is not erased
    from its old location. It behaves as if the first -setNeedsDisplay: was
    not called at all. (And in fact, on Leopard, if you remove the first
    -setNeedsDisplay:, you get the same artifacts.)

    What's the simplest way to fix this on all OSes?
  • > What's the simplest way to fix this on all OSes?

    [control display]; // clean up at old location
    [control setFrame:newFrame]; // move control
    [control setNeedsDisplay:YES]; // redraw at new location

    --
    I.S.
  • The call to -display will /erase/ from the old location? Really?
    That seems a little strange…

    I. Savant wrote:
    >> What's the simplest way to fix this on all OSes?
    >>
    >
    > [control display]; // clean up at old location
    > [control setFrame:newFrame]; // move control
    > [control setNeedsDisplay:YES]; // redraw at new location
    >
    > --
    > I.S.
    >
  • On 12/14/07, John Stiles <JStiles...> wrote:
    > The call to -display will /erase/ from the old location? Really?
    > That seems a little strange…

      Well ... no ... but then you're not really explaining the whole
    problem, so I was left to guess. :-) Could you provide more details?
    Where are the artifacts? Within the control or its superview?

    --
    I.S.
  • It should, but you may see some flicker as the update will happen in
    two parts.

    A better solution is to union the old and new frames and call
    setNeedsDisplayInRect:

    _murat

    On Dec 14, 2007, at 10:16 AM, John Stiles wrote:

    > The call to -display will /erase/ from the old location? Really?
    > That seems a little strange…
    >
    > I. Savant wrote:
    >>> What's the simplest way to fix this on all OSes?
    >>>
    >>
    >> [control display]; // clean up at old location
    >> [control setFrame:newFrame]; // move control
    >> [control setNeedsDisplay:YES]; // redraw at new location
    >>
    >> --
    >> I.S.
    >>

  • The artifacts are that the control isn't erasing itself from its old
    location. I just want the window to repaint itself at the control's old
    location.
    Maybe I could tell the superview to do setNeedsDisplayInRect… that might
    do it.

    I. Savant wrote:
    > On 12/14/07, John Stiles <JStiles...> wrote:
    >
    >> The call to -display will /erase/ from the old location? Really?
    >> That seems a little strange…
    >>
    >
    > Well ... no ... but then you're not really explaining the whole
    > problem, so I was left to guess. :-) Could you provide more details?
    > Where are the artifacts? Within the control or its superview?
    >
    > --
    > I.S.
    >
  • > A better solution is to union the old and new frames and call
    > setNeedsDisplayInRect:

      A better solution indeed. :-)

    --
    I.S.
  • Actually, you're right. I don't think Idiot's code will give you what
    you're after. But a call to the superview's setNeedsDisplayInRect: on
    the union of old and new frames should.

    _murat

    On Dec 14, 2007, at 10:16 AM, John Stiles wrote:

    > The call to -display will /erase/ from the old location? Really?
    > That seems a little strange…
    >
    > I. Savant wrote:
    >>> What's the simplest way to fix this on all OSes?
    >>>
    >>
    >> [control display]; // clean up at old location
    >> [control setFrame:newFrame]; // move control
    >> [control setNeedsDisplay:YES]; // redraw at new location
    >>
    >> --
    >> I.S.
    >>

  • > Maybe I could tell the superview to do setNeedsDisplayInRect… that might do
    > it.

      Exactly ... see _murat's response for a better approach (rather than
    doing it twice - once for each rect - union the rects together).

    --
    I.S.
  • On Dec 14, 2007, at 12:13 PM, John Stiles wrote:

    > I am writing code that moves a control from one place to another. In
    > Leopard, this works great:
    >
    > [control setNeedsDisplay:YES]; // clean up at old location
    > [control setFrame:newFrame]; // move control
    > [control setNeedsDisplay:YES]; // redraw at new location
    >
    > However, in Tiger, this doesn't work properly; the control is not
    > erased from its old location. It behaves as if the first -
    > setNeedsDisplay: was not called at all. (And in fact, on Leopard, if
    > you remove the first -setNeedsDisplay:, you get the same artifacts.)
    >
    > What's the simplest way to fix this on all OSes?

    Just a guess, but how about:

    [[control superview] setNeedsDisplay: YES];
    [control setFrame: newFrame];
    [control setNeedsDisplay: YES];

    (ideally, setNeedsDisplayInRect should probably be called instead to
    limit what the superview redraws)

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium | prime : build, mutate, evolve, animate : the next
    generation of fractal art
  • I just did a test and, in both Tiger and Leopard, you can do this and
    it works perfectly:

    [[control superview] setNeedsDisplayInRect:[control frame]];
    [control setFrame: newFrame];
    [[control superview] setNeedsDisplayInRect:[control frame]];

    On Dec 14, 2007, at 10:29 AM, glenn andreas wrote:

    >
    > On Dec 14, 2007, at 12:13 PM, John Stiles wrote:
    >
    >> I am writing code that moves a control from one place to another.
    >> In Leopard, this works great:
    >>
    >> [control setNeedsDisplay:YES]; // clean up at old location
    >> [control setFrame:newFrame]; // move control
    >> [control setNeedsDisplay:YES]; // redraw at new location
    >>
    >> However, in Tiger, this doesn't work properly; the control is not
    >> erased from its old location. It behaves as if the first -
    >> setNeedsDisplay: was not called at all. (And in fact, on Leopard,
    >> if you remove the first -setNeedsDisplay:, you get the same
    >> artifacts.)
    >>
    >> What's the simplest way to fix this on all OSes?
    >
    >
    > Just a guess, but how about:
    >
    > [[control superview] setNeedsDisplay: YES];
    > [control setFrame: newFrame];
    > [control setNeedsDisplay: YES];
    >
    > (ideally, setNeedsDisplayInRect should probably be called instead
    > to limit what the superview redraws)
    >
    > Glenn Andreas                      <gandreas...>
    > <http://www.gandreas.com/> wicked fun!
    > quadrium | prime : build, mutate, evolve, animate : the next
    > generation of fractal art
    >
    >
    >
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today