1.Create a cocoa application (not document-based)
2.Create a new class "StretchView"(subclass NSView)
3.Open the Interface builder and drag a "Scroll view" to the main window
4.Choose the "Scroll view" and set the class "StretchView" (in class identity window)
The size of the contentview is 500*500 and the size of the strechview is also 500*500 (horizontal Scroll is enabled).
Then I start to draw some numbers(1,2,3,4......) horizontally one after the other. When the number is out of ranger(the x pos is larger than 500) I increase the width of the StretchView. (Everything works fine up till this point)
Then I tried to make the horizontal scroller to automatically scroll to the end so that everytime I increase the width of the StretchView the last number coulde be seen.
Here's the code:
//The timer is called every sec
-(void)myTimerAction:(NSTimer *) timer
{
NSLog(@"myTimerAction");
//......
int i = _myArray.count;
NSRect rect = [self frame];
int width = rect.size.width;
//The width between two number is 10
//When the x pos of current num is bigger then the scroll's width
if((i * 10) > width) {
//reset the width
width = i * 10;
[self setFrameSize:CGSizeMake(width, rect.size.height)];
//How to make it autoscroll???
//...............................
}
//......
[self setNeedsDisplay:YES];
}