1

I'm using the method posted here to scroll an NSString across the screen. However, as shown in the image below, the string doesn't seem to be drawing correctly. Anyone have any ideas? Thanks.

enter image description here

EDIT: I forgot to mention that I modified the scrolling text class to use an attributed string rather than a regular string.

EDIT 2: I think the problem is that the string is repeating before it can finish the first time. How can I add some spacing before the string repeats itself?

Community
  • 1
  • 1
edc1591
  • 10,146
  • 6
  • 40
  • 63

2 Answers2

0

Try clearing the area before drawing by adding

NSRectFillUsingOperation(dirtyRect, NSCompositeClear);

at the beginning of drawRect:.

spudwaffle
  • 2,905
  • 1
  • 22
  • 29
  • When I add that it makes the view completely filled black – edc1591 Nov 01 '11 at 02:31
  • You don't need to set the drawing color when using `NSCompositeClear`. That operation doesn't use the drawing color; it always wipes the entire affected area. – Peter Hosey Nov 01 '11 at 02:34
  • @edc1591: Did you override `isOpaque` to return `YES`? If so, you aren't allowed to leave any part of the view unpainted (or cleared). If not, are you using spudwaffle's code unmodified? If you just use `NSRectFill(dirtyRect)`, that will fill with the current color using `NSCompositeCopy`; you want `NSCompositeClear`, which erases. – Peter Hosey Nov 01 '11 at 02:35
  • No, I didn't override `isOpaque`. Should I? I just used spudwafflle's code unmodified. – edc1591 Nov 01 '11 at 02:46
  • @edc1591: Like I said, if you override `isOpaque` and return `YES`, then you aren't allowed to leave any part of the view cleared. – Peter Hosey Nov 01 '11 at 03:07
  • Still, all I get is a black box. Overriding `isOpaque` doesn't fix it either. – edc1591 Nov 02 '11 at 02:28
  • Forgot to mention that I'm using an attributed string rather than a regular string. It looks like what's happening is the text is repeating before it ends, so it overlaps. – edc1591 Nov 03 '11 at 00:34
0

I figured it out. I had to change this line in drawRect::

otherPoint.x += dirtyRect.size.width;

to

otherPoint.x += (stringWidth + 20.0);

EDIT: You can change 20.0 depending on how much of a gap you want before the string repeats.

edc1591
  • 10,146
  • 6
  • 40
  • 63