performSelector:withObject:afterDelay: not working from scrollViewDidZoom
Posted
by oldbeamer
on Stack Overflow
See other posts from Stack Overflow
or by oldbeamer
Published on 2010-05-19T13:13:07Z
Indexed on
2010/05/19
13:40 UTC
Read the original article
Hit count: 274
Hi all, I feel like I should know this but I've been stumped for hours now and I've run out of ideas.
The theory is simple, the user manipulates the zoom and positioning in a scrollview using a pinch. If they hold that pinch for a short period of time then the scrollview records the zoom level and content offsets.
So I thought I'd start a performSelector:withObject:withDelay on the scrollViewDidZoom delegate method. If it expires then I record the settings. I delete the scheduled call every time scrollViewDidZoom is called and when the pinch gesture finishes.
This is what I have:
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
NSLog(@"resetting timer");
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(positionLock) object:nil];
[self performSelector:@selector(positionLock) withObject:nil afterDelay:0.4];
}
-(void)positionLock{
NSLog(@"position locked ");
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
NSLog(@"deleting timer");
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(positionLock) object:nil];
}
This is the output:
2010-05-19 22:43:01.931 resetting timer
2010-05-19 22:43:01.964 resetting timer
2010-05-19 22:43:02.231 resetting timer
2010-05-19 22:43:02.253 resetting timer
2010-05-19 22:43:02.269 resetting timer
2010-05-19 22:43:02.298 resetting timer
2010-05-19 22:43:05.399 deleting timer
As you can see the delay between the last and second last events should have been more than enough for the delayed selector call to execute.
If I replace performSelector:withObject:withDelay with plain old performSelector: I get this:
2010-05-19 23:08:30.333 resetting timer
2010-05-19 23:08:30.333 position locked
2010-05-19 23:08:30.366 resetting timer
2010-05-19 23:08:30.367 position locked
2010-05-19 23:08:30.688 deleting timer
Which isn't what I want but serves to show that it's only the delay that's causing it to not function, not something to do with the selector not being declared in the header, being misspelt or any other reason.
Any ideas as to why it's not working?
© Stack Overflow or respective owner