Skip to content

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

@litt1e-p

Description

@litt1e-p

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions