- 剛開始學習 swift 一段時間戚篙,學習果然還是還是要不停地敲代碼的啊五鲫,全部代碼都寫在導航控制器 UINavigationController 的類里面。先說下 swift 的整個控制器的側滑返回實現(xiàn)
- swift
- 1岔擂,第一種實現(xiàn)方法
// 獲取手勢屬性
/*
var count : UInt32 = 0
let ivars = class_copyIvarList(UIGestureRecognizer.self, &count)!
for i in 0..<count {
let nameP = ivar_getName(ivars[Int(i)])!
let name = String(cString: nameP)
print(name)//打印出所有屬性
}
free(ivars);
*/
//判斷并獲取 targets 的 action
guard let targets = interactivePopGestureRecognizer!.value(forKey: "_targets") as? [NSObject] else{return}
let targetObjc = targets[0]
let target = targetObjc.value(forKey: "target")
//由于直接使用它的 action 會崩潰位喂,所以自己需要重新構建一個 Selector,自定義一個手勢
let action = Selector(("handleNavigationTransition:"))
let panGes = UIPanGestureRecognizer(target: target, action: action)
view.addGestureRecognizer(panGes)
interactivePopGestureRecognizer!.delegate = self as? UIGestureRecognizerDelegate
object_setClass(interactivePopGestureRecognizer!.self, UIPanGestureRecognizer.classForCoder())
- OC 實現(xiàn)側滑(實現(xiàn)其實和 swift 差不多)
- 1塑崖,第一種實現(xiàn)方法
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UIGestureRecognizer class], &count);
//獲取手勢的屬性變量
for (int i = 0; i<count; i++) {
NSString *str = [NSString stringWithCString:ivar_getName(ivars[(int)i]) encoding:NSUTF8StringEncoding];
NSLog(@"%@",str);
}
free(ivars);
id targets = [self.interactivePopGestureRecognizer valueForKey:@"_targets"];
NSLog(@"%@",targets);
id target = [targets[0] valueForKey:@"target"];
//更具 target 獲取 selector
SEL selector = NSSelectorFromString(@"handleNavigationTransition:");
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:selector];
[self.view addGestureRecognizer:pan];
// 更換interactivePopGestureRecognizer的delegate為navigationController自己
self.interactivePopGestureRecognizer.delegate = self;
// 自帶的邊緣返回手勢UIScreenEdgePanGestureRecognizer痛倚,但只負責edge部分规婆。換成全屏的UIPanGestureRecognizer
object_setClass(self.interactivePopGestureRecognizer, [UIPanGestureRecognizer class]);
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者