IOS15之轻扫手势
ios中的手势,也是重点内容,必须学会使用。常见的有7大手势,今天介绍轻扫手势
UISwipeGestureRecognizer *swipeGes = [[UISwipeGestureRecognizer alloc] init];
swipeGes.direction = UISwipeGestureRecognizerDirectionLeft;
[self.tableView addGestureRecognizer:swipeGes];
[swipeGes addTarget:self action:@selector(swipe)];
}
-(void)swipe{
NSLog(@"%s",__func__);
}
给tableView添加轻扫手势,方向向左。
打印日志
2021-11-29 20:02:20.839891+0800 test1[14413:430937] -[ViewController swipe]
其写法跟 给UIButton 添加 事件差不多。
swift 写法:
override func viewDidLoad() {
super.viewDidLoad()
let swipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeClick))
swipe.direction = .left
view.addGestureRecognizer(swipe)
}
@objc private func swipeClick() -> Void {
debugPrint("swipeClick")
}
swift写法更加优雅简洁。
网友评论