WMPageController-Swift icon indicating copy to clipboard operation
WMPageController-Swift copied to clipboard

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

Open litt1e-p opened this issue 9 years ago • 1 comments

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.

litt1e-p avatar Sep 16 '16 00:09 litt1e-p

@litt1e-p thanks a lot!

wangmchn avatar Sep 18 '16 08:09 wangmchn