search

Home  >  Q&A  >  body text

IOS scrollView添加Timer后不响应scrollViewWillBeginDragging事件,这是为什么啊?

添加Timer代码

- (void) createTimer
{
    NSTimer *timer = [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(increaseCurrentPage) userInfo:nil repeats:YES];
    self.timer = timer;
    //消息循环
    NSRunLoop *runloop = [NSRunLoop currentRunLoop];
    [runloop addTimer:timer forMode:NSDefaultRunLoopMode];}

[self createTimer]viewDidLoad中调用,当不注释掉[self createTimer]的时候,

- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.timer invalidate];
    NSLog(@"draggged");
}

这段代码没有响应,不响应断点,只有当[self createTimer]注释掉之后,才会响应,这是为什么呢

阿神阿神2772 days ago637

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:14:30

     [runloop addTimer:timer forMode:NSDefaultRunLoopMode];

    Changed to:

     [runloop addTimer:timer forMode:NSRunLoopCommonModes];

    Try it!

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:14:30

    I would like to ask【NSTImer sch. . . 】What is the difference from init?

    reply
    0
  • Cancelreply