NSURLRequest won't fire while UIScrollView is scrolling

前端 未结 2 1858
猫巷女王i
猫巷女王i 2020-12-28 08:39

I have a problem in that I am trying to background load a sound file while the user moves around a UIScrollView... The problem is that I am using NSURLRequest so I can load

2条回答
  •  感情败类
    2020-12-28 09:10

    The NSURLRequest only manages the request, not the actual connection.

    Touch events such as scrolling will place the run loop into NSEventTrackingRunLoopMode. By default, an NSURLConnection is scheduled to only execute in NSDefaultRunLoopMode. So while in NSEventTrackingRunLoopMode, NSDefaultRunLoopMode is blocked.

    Good news is that you can schedule additional modes for an NSURLConnection, such as NSRunLoopCommonModes.

    connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
    [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    [connection start];
    

提交回复
热议问题