Skip to content

Instantly share code, notes, and snippets.

@software-mariodiana
Created December 3, 2017 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save software-mariodiana/bbe3117827aee322f72c8ae4c80e33e8 to your computer and use it in GitHub Desktop.
Save software-mariodiana/bbe3117827aee322f72c8ae4c80e33e8 to your computer and use it in GitHub Desktop.
Ensure UIView bounds method is called from main thread.
- (CGRect)bounds
{
// The architecture of the framework is such that bounds is sometimes accessed from a
// non-main thread. iOS 11 complains about this sort of thing.
__block CGRect theBounds = CGRectNull;
if ([NSThread isMainThread])
{
// Trying to grab the main thread if you're on the main thread causes deadlock.
theBounds = [super bounds];
}
else
{
// Submits a block object for execution on a dispatch queue and waits until that block completes.
dispatch_sync(dispatch_get_main_queue(), ^{
theBounds = [super bounds];
});
}
return theBounds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment