Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

petron

macrumors member
Original poster
May 22, 2009
95
0
Malmo, Sweden
Hi,
I just made the autoscroll challenge on ImageFun.

The autoscrolling supposed to be controlled by a timer every tenth of a second. In My case the work seems to be done but I have experienced one side effect, maybe a bug.

The side effect is following:

When I press the mouse down and move it outside the window the view is scrolled smoothly controlled by the timer. All looks fine, but when I keep the mouseDown outside the window and do not dragg it for some seconds the scroll image will move to the begining of the view. If I move the mouse it will immediatly moved as it should. .

The autoscroll method is invoked by the timer,while the timer is started from mouseDown: method. The timer is invalidated in mouseUp:

The invoked method looks like this

HTML:
- (void)scrollNow
{
    NSEvent *event = [NSApp currentEvent];
    [self autoscroll:event];
    [self setNeedsDisplay:YES];
}


Would it be a problem that the scrollNow is invoked all the time even while the mouse is not moving at all and thus the clever system finds out that maybe it is a time to reset the scroller back to start ?

Any idea would be appreciated, speciall from those of you who are working on Hillegass cocoa programming book.

/petron
 
Are there any Hillegass - readers that managed to reach chapter 24 ?
I really would like to verify the behaviour of autoscrolling.

/piotr
 
Are there any Hillegass - readers that managed to reach chapter 24 ?
I really would like to verify the behaviour of autoscrolling.

/piotr

On chapter 16! :) Afraid you are going to have to wait :(
 
OK mdeh,
I will wait. Let me know how it behaves at your place when you reach chapter 24. Works fine initailly but a bit irritating when the long mouse press with no movement activity causes a reset of auto scroll possition.
/piotr
 
Hi Peron,

In response to your post in my thread re Chapter 26...

Yes I have completed this challenge and my scroolNow method looks like this.

Code:
- (void)scrollNow:(NSTimer*)aTimer
{
	NSEvent *event = [NSApp currentEvent];
	[self autoscroll:event];
	[self setNeedsDisplay:YES];
}

Just like yours except for the:(NSTimer*)aTimer. I think you just left it off in your post because when I comment it out it will not work for me.

I am not getting the behavior you describe. I click and drag outside the window, and once it is completely scrolled it stops scrolling no mater how long I hold the mouse down.

Maybe the problem is in your mouseDown event. Here is my code for that...

Code:
- (void)mouseDown:(NSEvent *)event;
{
	NSPoint p = [event locationInWindow];
	downPoint = [self convertPoint:p fromView:nil];
	timer = [[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollNow:) userInfo:nil repeats:YES] retain];
	//[self setNeedsDisplay:YES];
}

John
 
Hi, John.

Yes my functions are nearly the same and I do have the (NSTimer *)mTimer as well. Any way I decided to copy your mouseDown to be exact copy and I still got the problem.
Then I realized that you are not using the garbage collection while I do.

So I went to "Target" changed the Garbage Collection to "unsuported", added in the code the retain and release, build it and now it works.

Seems like the Garbage Collector thinks that I pressed the mouse down for too long period without movements and it releases the timer. Seems strange. There is a chapter in the book about the garbage collectors, so maybe I will find out later what has happend and how to prevent from that behaviour.

Thanks again
/petron
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.