gpt4 book ai didi

ios - 取消隐藏工具栏在后台队列中不起作用?

转载 作者:行者123 更新时间:2023-11-28 22:03:36 24 4
gpt4 key购买 nike

我希望底部工具栏在 ScrollView 停止滚动时消失,这没问题:

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
self.toolbar.hidden = NO;
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
self.toolbar.hidden = NO;
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
self.toolbar.hidden = NO;
}

所以这很好用,但这种方法的问题是底部栏的外观像癫痫发作一样闪烁。我不想这样,所以我会让它休眠一秒钟,然后再出现。问题是 self.toolbar.hidden 在后台线程中没有响应:

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^{
NSLog(@"Hello?");
sleep(1);
self.toolbar.hidden = NO;
});
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^{
NSLog(@"Hello?");
sleep(1);
self.toolbar.hidden = NO;
});

}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^{
NSLog(@"Hello?");
sleep(1);
self.toolbar.hidden = NO;
});
}

所以在这种情况下,self.toolbar.hidden = NO; 什么都不做。 NSLogs 没有问题,所以我想我会尝试这种方法,但它也不起作用:

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^{
NSLog(@"Hello?");
sleep(1);
[self unhideToolbar];
});
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^{
NSLog(@"Hello?");
sleep(1);
[self unhideToolbar];
});

}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^{
NSLog(@"Hello?");
sleep(1);
[self unhideToolbar];
});
}

-(void)unhideToolbar
{
NSLog(@"toolbar unhidden");
self.toolbar.hidden = NO;
}

我不知道我在这里做错了什么...所有 NSLog 都没有问题,但是取消隐藏工具栏与异步功能无关。

有人知道为什么会这样吗?

最佳答案

UI 更改必须在主队列中。尝试像这样将返回发送给它:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^{
NSLog(@"Hello?");
sleep(1);
dispatch_async(dispatch_get_main_queue(), ^{
[self unhideToolbar];
});
});

关于ios - 取消隐藏工具栏在后台队列中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24520527/

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