開篇
在iOS中,默認(rèn)如果有導(dǎo)航控制器,當(dāng)push到下一個控制器時,當(dāng)前界面時可以局部側(cè)滑返回的,這一段范圍很少.
既然系統(tǒng)已經(jīng)給我們了實現(xiàn)好了,側(cè)滑返回,那么我們?nèi)绾谓鉀Q,全屏手勢側(cè)滑返回呢?
方案
拿到系統(tǒng)的返回手勢,操作一波
runtime 打印導(dǎo)航控制器所有私有屬性
/// 通過runtime獲取對應(yīng)的手勢屬性
var count : UInt32 = 0
let ivars = class_copyIvarList(UIGestureRecognizer.self, &count)!
for i in 0..<count {
let ivar = ivars[Int(i)]
let namep = ivar_getName(ivar)
let name = String(cString: namep!)//屬性名稱
print(name)
}
打印結(jié)果:
_gestureFlags
_targets // 這個保存手勢的所有target
_delayedTouches
_delayedPresses
_view
_lastTouchTimestamp
_firstEventTimestamp
_state
_allowedTouchTypes
_initialTouchType
_internalActiveTouches
_forceClassifier
_requiredPreviewForceState
_touchForceObservable
_touchForceObservableAndClassifierObservation
_forceTargets
_forcePressCount
_beganObservable
_failureRequirements
_failureDependents
_activeEvents
_keepTouchesOnContinuation
_delegate
_allowedPressTypes
_name
_gestureEnvironment
獲取target
guard let anyObject = interactivePopGestureRecognizer!.value(forKey: "_targets") as? [AnyObject] else {
return
}
let object = anyObject.first
print(object)
打印結(jié)果:
/// 原來是一個數(shù)組,數(shù)組中是一個tuple, tuple第一個是一個action,第二個既然是target對象
[(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fc664e4f850>)]
KVC 取出target
let target = object.value(forKeyPath: "target")
let action = Selector(("handleNavigationTransition:"))
//下面是獲取不到action的會奔潰
//let action = object.value(forKeyPath: "action") as? Selector
替換手勢
//創(chuàng)建自己的手勢 將系統(tǒng)的手勢去代替自己創(chuàng)建的手勢
let panGes = UIPanGestureRecognizer(target: target, action: action)
view.addGestureRecognizer(panGes)
使用FDFullscreenPopGesture
這玩意就補(bǔ)多少了,添加進(jìn)去,啥都不用干,懶人方案,完美解決古徒。