gpt4 book ai didi

iphone - UI 卡住并以动画方式删除 UIScrollView subview

转载 作者:行者123 更新时间:2023-12-03 20:00:37 30 4
gpt4 key购买 nike

在我的 iPhone 应用程序中,我有一个带有自定义内容 View 的 UIScrollView。在某些时候,自定义弹出 View 会动态添加到内容中,并带有出现和消失的缩放动画。我使用基于 block 的动画和一个完成处理程序,该处理程序调用 [self removeFromSuperView],如下所示:

- (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];
}];
}

大多数情况下这是有效的,但是在这个动画之后,UI 会时不时地完全锁定并且对任何触摸都没有响应。我很确定这个动画是问题的根源,因为动画代码被注释掉了,我无法重现它。使用调试器进行中断,所有三个线程似乎都处于空闲状态:

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

Instruments 显示我的应用程序不占用 CPU 时间,因此存在某种死锁。谁能阐明这种行为以及如何避免这种行为?

更新:我做了更多挖掘并使用传统动画 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];
}

最佳答案

您应该为您的动画尝试这种方法:+animateWithDuration:delay:options:animations:completion:

带有选项:UIViewAnimationOptionAllowUserInteraction

关于iphone - UI 卡住并以动画方式删除 UIScrollView subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3823154/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com