Last active
February 10, 2016 17:05
-
-
Save dianqk/df41ba56ceb35e0242b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
func recurisiveSearchParentViewUntil<T: UIView>(type: T.Type, currentView: UIView) -> T? { | |
switch currentView { | |
case let view as T: | |
return view // 当前 view 满足则返回 view | |
case let view where view.superview != nil: | |
return recurisiveSearchParentViewUntil(type, currentView: view.superview!) | |
default: | |
return nil | |
} | |
} |
jasl
commented
Feb 10, 2016
func recurisiveSearchParentViewUntil<T: UIView>(type: T.Type, currentView: UIView?) -> T? {
guard let currentView = currentView else { return nil }
return (currentView as? T) ?? recurisiveSearchParentViewUntil(type, currentView: currentView.superview)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment