Reputation: 2209
I am using RNFrostedSidebar for leftmenu. While dismissing the sidebar, below block of code is executing
- (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);
}
}
After dismissAnimated method executed i want to run a code to update the HomeViewController, That code is
[self callNavBar];
-(void) callNavBar {
[[NSNotificationCenter defaultCenter] postNotificationName:@"adjustNavBar"
object:self];
}
i tried this solution, like adding the methods in queue and executing but i got exception as
"Main Thread Checker: UI API called on a background thread: -[UIView bounds]"
Then i tried this too got the same error as above.
Upvotes: 0
Views: 594
Reputation: 12154
Your problem is because you didn't update ui inside UI thread. To resolve it, call dismissAnimated:completion:
method inside main queue.
- (void)handleTap:(UIPanGestureRecognizer *)recognizer {
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissAnimated:YES completion:^(BOOL finished) {
[self callNavBar];
}];
});
}
Upvotes: 1
Reputation: 1
You can put the function as the completion handler here, instead of nil. That way it will run exactly when you want it.
It would look somewhat like this.
- (void)handleTap:(UIPanGestureRecognizer *)recognizer {
[self dismissAnimated:YES completion:[self callNavBar]];
}
Upvotes: -1