0

I try to call a method after a delay when the user start to dragging a scrollView.

This block below is called but the action define in this performselector: is called only when I stop to drag the scrollView

- (void)viewDidLoad {
    [super viewDidLoad];
    UIScrollView *sv = [[UIScrollView alloc] initWithFrame:self.view.frame];
    sv.delegate = self;
    sv.backgroundColor = [UIColor redColor];
    [sv setContentSize:CGSizeMake(1000, 200)];
    [self.view addSubview:sv];
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    NSLog(@"hey");
    [self performSelector:@selector(myAction) withObject:nil afterDelay:3];
}

- (void)myAction
{
    NSLog(@"Called 3secondes after begin dragging");
}

I also try with a NSTimer and in the background thread but the problem is the same...

Any Idea?

Damien Romito
  • 9,801
  • 13
  • 66
  • 84
  • Well i just tried and it works for me. Are you sure the delegate is well set ? or that your function "myAction" doesnt take parameter ? – John Smith Oct 27 '14 at 11:12
  • Yes, I'm sure cause "MyAction" is called when "scrollViewDidEndDragging"..I know it's very strange. – Damien Romito Oct 27 '14 at 11:35
  • I've just tried with an empty project, and I have the same problem: "MyAction" is called only when I end dragging – Damien Romito Oct 27 '14 at 11:47

1 Answers1

2

If you want to have the callback fired while you're still dragging, you must schedule it for Common Run Loop modes, like so:

[self performSelector:@selector(myAction) withObject:nil afterDelay:3 inModes:@[NSRunLoopCommonModes]];

That'll do the trick :)

Bartek Chlebek
  • 1,665
  • 1
  • 16
  • 23