2
我跟着一個代碼,當用戶在屏幕上向左/向右滑動時切換選項卡。問題是,當我切換到其他選項卡時,選項卡欄消失。Objective-C切換標籤使用滑動
我試着推導航控制器,但它會拋出一個錯誤,說它不被支持。
下面是代碼:
- (void)viewDidLoad {
[super viewDidLoad];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
swipeLeft.delegate = self;
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
swipeRight.delegate = self;
}
-(void) swipeRight:(UISwipeGestureRecognizer *) recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionRight){
//NSLog(@"swipe right");
NSString * storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"RecentsController"];
[self presentViewController:vc animated:YES completion:nil];
}
}
-(void) swipeLeft:(UISwipeGestureRecognizer *) recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
NSLog(@"Swipe left");
NSString * storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"SettingsController"];
[self presentModalViewController:vc animated:YES];
}