我有一个不同的 UIStoryboard UIViewControllers
,我想添加另一个UIViewController
(如仪表板),当用户从左侧滑动 ipad 时,仪表板将出现,然后当他向后滑动时,当前视图将被恢复。
这可能吗?如果是的话,任何提示如何做或任何好的教程UIGestureRecognizer
?
谢谢你。
我有一个不同的 UIStoryboard UIViewControllers
,我想添加另一个UIViewController
(如仪表板),当用户从左侧滑动 ipad 时,仪表板将出现,然后当他向后滑动时,当前视图将被恢复。
这可能吗?如果是的话,任何提示如何做或任何好的教程UIGestureRecognizer
?
谢谢你。
UISwipeGestureRecognizer * swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeleft];
//向右滑动
UISwipeGestureRecognizer * swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)];
swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swiperight];
// 实现手势方法
-(void)swipeleft:(UISwipeGestureRecognizer*)gestureRecognizer
{
//Do what you want here
}
-(void)swiperight:(UISwipeGestureRecognizer*)gestureRecognizer
{
//Do what you want here
}
试试这个。
这是上述代码的快速版本。
向左滑动
var swipeleft = UISwipeGestureRecognizer(target: self, action: Selector("swipeleft:"))
swipeleft.direction = .left
view.addGestureRecognizer(swipeleft)
向右滑动
var swiperight = UISwipeGestureRecognizer(target: self, action: Selector("swiperight:"))
swiperight.direction = .right
view.addGestureRecognizer(swiperight)
方法实现...
@objc func swiperight(sender: UITapGestureRecognizer? = nil) {
// Do what u want here
}
@objc func swipeleft(sender: UITapGestureRecognizer? = nil) {
// Do what u want here
}