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
| extension UIPageViewController { | |
| var bk_scrollView: UIScrollView? { | |
| if let v = view as? UIScrollView { | |
| return v // 事实上,view不是UIScrollView类型 | |
| } | |
| for v in view.subviews where v is UIScrollView { | |
| return v as? UIScrollView // view.subviews 只有一个元素,其类型是 _UIQueuingScrollView,是 UIScrollView 的子类 | |
| } | |
| return nil |
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
| // 如果 UIViewController.view.addSubView(scrollView),会导致屏幕左边缘的返回手势失效。 | |
| // 解决办法如下: | |
| if let ges = navigationController?.interactivePopGestureRecognizer { | |
| scrollView.panGestureRecognizer.require(toFail: ges) // 允许左边缘手势返回 | |
| } | |
| // 对于 UIPageViewController,可以先找到其 scrollView,再如法炮制 |
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
| // 1. file url 与 path 转换 | |
| let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory()) | |
| let path = tmpURL.path // | |
| // 事实上,tmpURL.absoluteString得到的是 file:// 格式,而path是没有协议(scheme)部分的,应以slash开头。 | |
| // 2. 检查文件存在性 |
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
| // Let's declare two structs that with different variables and different boolean values: | |
| struct A { | |
| let x = true | |
| } | |
| struct B { | |
| let y = false | |
| } |
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
| UIDebuggingInformationOverlay is private class created by Apple. | |
| http://ryanipete.com/blog/ios/swift/objective-c/uidebugginginformationoverlay/ | |
| https://www.raywenderlich.com/177890/swizzling-in-ios-11-with-uidebugginginformationoverlay | |
| FLEX is preferred, | |
| https://github.com/Flipboard/FLEX |
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
| po view.recersiveDescription 可以输出整个view层次 | |
| po Thread.callStackSymbols 输出栈信息 |
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
| // textField included by a cell, and the cell included by a scrollView | |
| override func willMove(toWindow newWindow: UIWindow?) { | |
| super.willMove(toWindow: newWindow) | |
| if newWindow == nil { | |
| NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillChangeFrame, object: nil) | |
| } else { | |
| NotificationCenter.default.addObserver(self, selector: #selector(keyboardFrameWillChange(_:)), name: .UIKeyboardWillChangeFrame, object: nil) | |
| } | |
| } |
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
| extension WKWebView { | |
| /// sync version | |
| /// | |
| /// - Parameters: | |
| /// - js: 要执行的javascript代码 | |
| /// - timeout: 限时返回(单位秒),0表示不限时 | |
| /// - Returns: 执行结果 | |
| func evaluatingJavaScript(_ js: String, timeout: TimeInterval = 0) -> Any? { | |
| var res: Any? = nil | |
| var finish = false |
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
| // 这两个方法有冲突(调用时无法区分),除非其中一个去掉IndexPath后的问号 | |
| /// 不能有默认参数 nil,因为inout不能操作常量 | |
| func shouldChange(indexPath: inout IndexPath?) -> Bool { | |
| indexPath = IndexPath(item: 0, section: 1) | |
| return true | |
| } | |
| /// 可以有默认参数 nil, | |
| func shouldChange(indexPath: UnsafeMutablePointer<IndexPath?>? = nil) -> Bool { |
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
| // 1. URL 转为 URLComponents 时,什么时候会变成 nil | |
| // 2. URLComponents 转为 URL 时,什么时候会变成 nil | |
| // 3. URL 协议后不带双斜杠时,为什么 host 会变成 path(如下例) | |
| let str = "http:im.qq.com" // "mailto:someone@example.com" | |
| if let url = URL(string: str), let uc = URLComponents(url: url, resolvingAgainstBaseURL: true) { | |
| print(url) | |
| print(uc, uc.url!) | |
| print(uc.scheme!, uc.path) |