Event tracking in UIScrollView blocks the main thread. Any corrections?

Event tracking in UIScrollview blocks the main thread. I use the main thread to start a timer that controls some animation - the result is that any user interaction with the scrollable view (drag up or down, etc.) forces the animation to freeze (running along the main runloop). Is there any way around this?

I tried RTFM about NSRunloop (CFRunLoopAddCommonMode and others), but it is pretty brief, which led me to believe that it is better to avoid redistributing event priorities / thread priorities. Does anyone have an understanding?

+5
source share
2 answers

NSTimer "" :

let timer = Timer.init(timeInterval: 10, repeats: false) { (_) in
    // ... do something useful after 10 seconds ...
}
RunLoop.main.add(timer, forMode: .commonModes)

NSTimer *timer = [[NSTimer alloc] initWithFireDate: [NSDate dateWithTimeIntervalSinceNow: delayInSeconds] interval: 0 target:yourObject selector:yourSelector userInfo:nil repeats:NO];
[NSRunLoop.mainRunLoop addTimer: timer forMode: NSRunLoopCommonModes];

, , , NSRunLoopCommonModes.

, , " ". NSTimer , . , NSRunLoopCommonModes , .

+17

, . , , , .

Edit:

, , UIScrollView . ( ) , (.. -scrollviewDidScroll ..) UIScrollView. , , , .

0

All Articles