UI freeze with animated UIScrollView subtitle deletion

In my iPhone application, I have a UIScrollView with custom content views. In some cases, a custom pop-up view is dynamically added to content with zoom animations appearing and disappearing. I use block animations with a completion handler that calls [self removeFromSuperView] as follows:

- (void)dismissPopup {
    CGRect rect = self.frame;
    rect.origin.y += rect.size.height/2 * (pointingDown ? 1 : -1);
    [UIView animateWithDuration:kZoomDuration
                     animations:^{
                         self.frame = rect;
                         self.transform = CGAffineTransformMakeScale(0.01, 0.01);
                     }
                     completion:^(BOOL finished) {
                         [self removeFromSuperview];
                     }];
}

This basically works, but from time to time after this animation, the user interface is completely blocked and does not respond to any clicks. I am sure that this animation is the source of the problem, since the animation code is commented out, I could not play it. Interacting with the debugger, all three threads seem to be idle:

Thread-1
#0  0x32fd1c98 in mach_msg_trap
#1  0x32fd3d6a in mach_msg
#2  0x34432c3e in __CFRunLoopServiceMachPort
#3  0x344324c8 in __CFRunLoopRun
#4  0x34432276 in CFRunLoopRunSpecific
#5  0x3443217e in CFRunLoopRunInMode
#6  0x3026b5f2 in GSEventRunModal
#7  0x3026b69e in GSEventRun
#8  0x31ad0122 in -[UIApplication _run]
#9  0x31ace12e in UIApplicationMain
#10 0x00002b06 in main at main.m:14

Thread-2
#0  0x32ffe330 in kevent
#1  0x330a7b74 in _dispatch_mgr_invoke
#2  0x330a75c4 in _dispatch_queue_invoke
#3  0x330a7764 in _dispatch_worker_thread2
#4  0x3304b680 in _pthread_wqthread

Thread-3
#0  0x32fd1c98 in mach_msg_trap
#1  0x32fd3d6a in mach_msg
#2  0x34432c3e in __CFRunLoopServiceMachPort
#3  0x344324c8 in __CFRunLoopRun
#4  0x34432276 in CFRunLoopRunSpecific
#5  0x3443217e in CFRunLoopRunInMode
#6  0x34b524e8 in RunWebThread
#7  0x3304b284 in _pthread_start

, , . - ?

: , API , , , . ​​ ?

- (void)dismissPopup {
    CGRect rect = self.frame;
    rect.origin.y += rect.size.height/2 * (pointingDown ? 1 : -1);
    [UIView beginAnimations:@"dismissPopup" context:nil];
    [UIView setAnimationDuration:kZoomDuration];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    self.frame = rect;
    self.transform = CGAffineTransformMakeScale(0.01, 0.01);
    [UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [self removeFromSuperview];
}
+3
2

, : +animateWithDuration:delay:options:animations:completion:

: UIViewAnimationOptionAllowUserInteraction

+2

, - , ( - ui , ).. ,

[self performSelectorOnMainThread: @selector (animationFunctionGoesHere) withObject: nil waitUntilDone: YES];

0

Source: https://habr.com/ru/post/1767191/


All Articles