cocoa - Autoscroll problen -
1.create cocoa application (not document-based)
2.create new class "stretchview"(subclass nsview)
3.open interface builder , drag "scroll view" main window
4.choose "scroll view" , set class "stretchview" (in class identity window)
the size of contentview 500*500 , size of strechview 500*500 (horizontal scroll enabled).
then start draw numbers(1,2,3,4......) horizontally 1 after other. when number out of ranger(the x pos larger 500) increase width of stretchview. (everything works fine till point)
then tried make horizontal scroller automatically scroll end everytime increase width of stretchview last number coulde seen.
here's code:
//the timer called every sec -(void)mytimeraction:(nstimer *) timer { nslog(@"mytimeraction"); //...... int = _myarray.count; nsrect rect = [self frame]; int width = rect.size.width; //the width between 2 number 10 //when x pos of current num bigger scroll's width if((i * 10) > width) { //reset width width = * 10; [self setframesize:cgsizemake(width, rect.size.height)]; //how make autoscroll??? //............................... } //...... [self setneedsdisplay:yes]; }
try this:
nsview *contentview = [[self enclosingscrollview] contentview]; cgfloat newxposition = width - nswidth([contentview bounds]); if (newxposition > 0.0) [self scrollpoint:nsmakepoint(newxposition, 0.0)];
contentview
clipping view in enclosing scroll view. want scroll current view x point in view such x point + clipping view width give last clipping view width points of view.
Comments
Post a Comment