我正在使用RNFrostedSidebar对于左侧菜单。关闭侧边栏时,正在执行下面的代码块
- (void)handleTap:(UIPanGestureRecognizer *)recognizer {
[self dismissAnimated:YES completion:nil];
}
- (void)dismissAnimated:(BOOL)animated completion:(void (^)(BOOL finished))completion {
void (^completionBlock)(BOOL) = ^(BOOL finished){
[self rn_removeFromParentViewControllerCallingAppearanceMethods:YES];
rn_frostedMenu = nil;
if (completion) {
completion(finished);
}
};
if (animated) {
CGFloat parentWidth = self.view.bounds.size.width;
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = self.showFromRight ? parentWidth : -_width;
CGRect blurFrame = self.blurView.frame;
blurFrame.origin.x = self.showFromRight ? parentWidth : 0;
blurFrame.size.width = 0;
self.blurView.frame = blurFrame;
self.blurView.alpha=0.1;
[UIView animateWithDuration:self.animationDuration delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.viewForTable.frame = contentFrame;
}
completion:completionBlock];
} else {
completionBlock(YES);
}
}
执行dismissAnimated方法后,我想运行代码来更新HomeViewController,该代码是
[self callNavBar];
-(void) callNavBar {
[[NSNotificationCenter defaultCenter] postNotificationName:@"adjustNavBar"
object:self];
}
我试过this解决方案,例如在队列中添加方法并执行,但我遇到异常
"Main Thread Checker: UI API called on a background thread: -[UIView bounds]"
然后我尝试了this too遇到与上面相同的错误。
最佳答案
您的问题是因为您没有在 UI 线程内更新 ui。要解决此问题,请在主队列中调用 dismissAnimated:completion:
方法。
- (void)handleTap:(UIPanGestureRecognizer *)recognizer {
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissAnimated:YES completion:^(BOOL finished) {
[self callNavBar];
}];
});
}
关于ios - block 方法完成后执行方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58137255/