Swift一款絲滑的側滑返回
SwiftFullScreenPop - 基於Swift3.0實現全屏側滑返回
Features
- 解決自定義navigationBar側滑返回不能用快速幫你實現側滑返回功能。
- 解決當某個介面navigationBar隱藏時下個介面有導航導致側滑返回體驗很差。
- 解決UIScrollView不能使用側滑返回。
CocoaPods
platform :ios, '7.0'
target 'Your Project' do
pod 'SwiftFullScreenPop'
end
Usage
- 在需要使用的地方匯入標頭檔案
import SwiftFullScreenPop
- 可以在自己的UINavigationController基類裡面加入下面程式碼
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
UINavigationController.swizzle()
UIViewController.viewControllerSwizzle()
}
- 在ViewController裡面直接使用
// 不支援側滑true
isInteractivePopDisable = true
// 隱藏當前頁面導航
self.isPrefersNavigationBarHidden = true
Swizzle
- 基於extension UInavigationController 和 extension UIViewController實現swizzle controller push function;viewWillAppear and ViewWillDisappear
DispatchQueue.once(token: Static.token) {
let originalSelector = #selector(UINavigationController.pushViewController(_:animated:))
let swizzlerSelector = #selector(UINavigationController.myPushViewController(_:animated:))
let originalMethod = class_getInstanceMethod(UINavigationController.self, originalSelector)
let swizzlerMethod = class_getInstanceMethod(UINavigationController.self, swizzlerSelector)
//在進行 Swizzling 的時候,需要用 class_addMethod 先進行判斷一下原有類中是否有要替換方法的實現
let isAddMethod = class_addMethod(UINavigationController.self, originalSelector, method_getImplementation(swizzlerMethod), method_getTypeEncoding(swizzlerMethod))
if isAddMethod
{
class_replaceMethod(UINavigationController.self, swizzlerSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
}else {
method_exchangeImplementations(originalMethod, swizzlerMethod)
}
}
DispatchQueue.once(token: Static.token) {
let originalSelector = #selector(UIViewController.viewWillAppear(_:))
let swizzlerSelector = #selector(UIViewController.myViewWillApper(_:))
let originalMethod = class_getInstanceMethod(self, originalSelector)
let swizzlerMethod = class_getInstanceMethod(self, swizzlerSelector)
let isAddMethod: Bool = class_addMethod(self, originalSelector, method_getImplementation(swizzlerMethod), method_getTypeEncoding(swizzlerMethod))
if isAddMethod
{
class_replaceMethod(self, swizzlerSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
}else {
method_exchangeImplementations(originalMethod, swizzlerMethod)
}
let disappear_originalSEL = #selector(UIViewController.viewWillDisappear(_:))
let disappear_swizzleSEL = #selector(UIViewController.myViewWillDisappear(_:))
let disappear_originalMethod = class_getInstanceMethod(self, disappear_originalSEL)
let disappear_swizzleMethod = class_getInstanceMethod(self, disappear_swizzleSEL)
let isAdd: Bool = class_addMethod(self, disappear_originalSEL, method_getImplementation(disappear_swizzleMethod), method_getTypeEncoding(disappear_swizzleMethod))
if isAdd {
class_replaceMethod(self, disappear_swizzleSEL, method_getImplementation(disappear_originalMethod), method_getTypeEncoding(disappear_originalMethod))
}else {
method_exchangeImplementations(disappear_originalMethod, disappear_swizzleMethod)
}
}
- 具體看本文Demo程式碼。
- 我的:github
在實現cocoaPods遇到的坑
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
在終端裡面執行:echo "3.0" > .swift-version
- 如果提示Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.
重新在終端裡面執行:pod trunk register 郵箱名 “使用者名稱”
再到郵箱裡面重新驗證即可 - 如果想知道如何實現自己的程式碼用cocoapods管理可移動我的簡書文章
順便提及下關於本地的程式碼如何git管理主要以下幾步
- git init. //當前需要提交的檔案路徑,和github上面XXXX.git一致
- git add filename
- git commit -m '提交資訊說明' //新增描述
- git pull //資料同步
- git push origin master //提交資料
- 遇到如下錯誤
error: failed to push some refs to 'git@github.com:LeeFengHY/SwiftFullScreenPop.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
是因為遠端repository和我本地的repository衝突導致的,如下解決方法:
- 1:
git pull origin master
git push -u origin master
- 2:若不想merge遠端和本地修改,可以先建立新的分支:
git branch [name]
git push -u origin [name]
聯絡
- 留言或者加我QQ:578545715
相關文章
- iOS 如何絲滑的側滑返回iOS
- Swift全屏滑動返回Swift
- Android側滑(右滑、下拉)返回控制元件 - SwipeBackLayoutAndroid控制元件
- Activity側滑返回的實現原理
- Flutter 仿iOS側滑返回案例實現FlutteriOS
- 給你的頁面帶上側滑返回——SlideBackIDE
- Android側滑返回分析和實現(不高仿微信)Android
- mui關閉側滑UI
- Linux下絲滑使用dockerLinuxDocker
- 《iPhone側滑不相容-mui》iPhoneUI
- 讓你的網頁更絲滑(一)網頁
- 讓你的網頁更絲滑(全)網頁
- 仿 “即刻APP” 滑動返回的效果APP
- Android入門教程 | DrawerLayout 側滑欄Android
- ItemTouchHelper實現可拖拽和側滑的列表
- AI讓你看片更絲滑AI
- flutter系列之:如絲般順滑的SliverAppBarFlutterAPP
- 原生Android 側滑選單實踐(部分)Android
- Android自定義View(四)側滑佈局AndroidView
- vue移動端側滑皮膚元件Vue元件
- 讓web擁有原生手機側滑選單那種順滑外掛Web
- 當 Kotlin 遇上 Android KTX,豈止絲滑?KotlinAndroid
- 攻擊域控絲滑小連招
- 如此絲滑的API設計,用起來真香API
- Kubernetes 升級不棄 Docker:KubeKey 的絲滑之道Docker
- Flutter 側滑欄及城市選擇UI的實現FlutterUI
- Webpack DllPlugin 讓構建速度柔順絲滑WebPlugin
- 《瞬變》原來變好可以如此絲滑!
- Go Ballast 讓記憶體控制更加絲滑GoAST記憶體
- docker容器編排原來這麼絲滑~Docker
- 如何把 Caffeine Cache 用得如絲般順滑?
- 讓Vue專案更絲滑的幾個小技巧Vue
- iOS 實現UINavigation全屏滑動返回(二)iOSUINavigation
- css3實現側邊滑動選單CSSS3
- uniapp---app滑動翻頁(上滑、下滑、左滑、右滑)APP
- 擼一款”靈動“的滑動按鈕
- 如何優雅絲滑地從Date過渡到LocalDateTimeLDA
- vue-router 手勢滑動觸發返回Vue
- iOS開發UI篇--一個側滑選單SlidingMenuiOSUI