如何将手势切换回上一个视图 ios?
Posted
技术标签:
【中文标题】如何将手势切换回上一个视图 ios?【英文标题】:How to swipe gesture segue back to previous view ios? 【发布时间】:2014-01-08 05:17:56 【问题描述】:我试图回到(QueryController)我来自的视图。 但是没有滑动动作发生...... 不知道我错过了什么。
@implementation ProfileController4
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
// Custom initialization
UISwipeGestureRecognizer * Swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)];
Swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:Swiperight];
UISwipeGestureRecognizer * Swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
Swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:Swipeleft];
return self;
-(void)swipeleft:(UISwipeGestureRecognizer*)gestureRecognizer
//Do what you want here
-(void)swiperight:(UISwipeGestureRecognizer*)gestureRecognizer
//Do what you want here
[self performSegueWithIdentifier: @"friendsBackToQuerySeg" sender: self];
// [[UIViewController alloc] initWithNibName:@"QueryController1" bundle:nil];
【问题讨论】:
使用 Navigation Stack 并将 ViewController 推送到手势的选择器目标 在viewDidLoad
方法中添加initWithNibName
代码。
感谢@Dilip 等人。放入 viewDidLoad 方法修复了它。现在可以使用了。
【参考方案1】:
在viewDidLoad
方法中添加您的UISwipeGestureRecognizer
代码..
- (void)viewDidLoad
[super viewDidLoad];
UISwipeGestureRecognizer * Swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)];
Swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:Swiperight];
UISwipeGestureRecognizer * Swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
Swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:Swipeleft];
【讨论】:
以上是关于如何将手势切换回上一个视图 ios?的主要内容,如果未能解决你的问题,请参考以下文章
从 Tab View Controller 切换到滑动手势时的 iOS Xcode 问题