Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS10 bug? NSClassFromString("_UINavigationBarBackground") gets nil? #16

Open
litt1e-p opened this issue Sep 16, 2016 · 1 comment
Open

Comments

@litt1e-p
Copy link
Contributor

litt1e-p commented Sep 16, 2016

hi, @wangmchn , my app crashed when I run it in iOS10 phone, it gets an error that fatal error: unexpectedly found nil while unwrapping an Optional value, this error perhaps caused by func: adjustMenuViewFrame, iOS 10 does not has this class : NSClassFromString("_UINavigationBarBackground")?, I have tried to fix it and it works by below codes:

for subview in (navigationController?.navigationBar.subviews)! {
                // add a guard to filter that missing class: _UINavigationBarBackground
                guard let _ = NSClassFromString("_UINavigationBarBackground") else {
                    continue
                }
                guard !subview.isKindOfClass(NSClassFromString("_UINavigationBarBackground")!) && !subview.isKindOfClass(MenuView.self) && (subview.alpha != 0) && (subview.hidden == false) else { continue }

                let maxX = CGRectGetMaxX(subview.frame)
                if maxX < viewWidth / 2 {
                    let leftWidth = maxX
                    menuX = menuX > leftWidth ? menuX : leftWidth
                }
                let minX = CGRectGetMinX(subview.frame)
                if minX > viewWidth / 2 {
                    let width = viewWidth - minX
                    rightWidth = rightWidth > width ? rightWidth : width
                }

            }

I don't know whether it will cause other bug, or maybe it not the correct way to avoid the crash.

Environment: Xcode8, Swift2.3, iOS 10

thanks.

@wangmchn
Copy link
Owner

@litt1e-p thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants