1

What I have Done !!

1) I can swipe between view controllers(View1,and View2 ) as showing in the image below

Image 1

2) I Created Tow button in ContainerViewController That will allow The user to Click each button to navigate between these two pages [Similar to the swipe but this one with button click]

Here's The Big Picture how my Program Looks like in the image below

Image 2

What help do I need ?

1) I want someone to help me to Implement these Two button to navigate between these two pages [Similar to the swipe ]. In addition, The user can either swipe or click the buttons to Navigate between pages.

It will be my pleasure to find someone here who's willing to help me and others

1-ContainerViewController I just only created two buttons.

2- View1 and View2 I have not done any coding here.

3- ViewSwipe Here's The code

#import "ScrollViewController.h"
#import "View1.h"
#import "View2.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    View1 * V1 = [[View1 alloc]initWithNibName:@"View1" bundle:nil];
    View2 * V2 = [[View2 alloc]initWithNibName:@"View2" bundle:nil];



    [self addChildViewController:V1];
    [self.scrollView addSubview:V1.view];
    [V1 didMoveToParentViewController:self];


    [self addChildViewController:V2];
    [self.scrollView addSubview:V2.view];
    [V2 didMoveToParentViewController:self];

    CGRect V2Frame = V2.view.frame;
    V2Frame.origin.x= self.view.frame.size.width;
    V2.view.frame = V2Frame;

    self.scrollView.contentSize=CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height);

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Assam AlZookery
  • 479
  • 4
  • 15

2 Answers2

2

You can achieve that as Darji said by using UISwipeGestureRecognizer

- (void)viewDidLoad {
    [super viewDidLoad];
    UISwipeGestureRecognizer *leftToRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftToRightSwipeDidFire)];
    leftToRightGesture.direction = UISwipeGestureRecognizerDirectionRight;
    [self.tabBarController.tabBar addGestureRecognizer:leftToRightGesture];

    UISwipeGestureRecognizer *rightToLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightToLeftSwipeDidFire)];
    rightToLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.tabBarController.tabBar addGestureRecognizer:rightToLeftGesture];
}


- (void)leftToRightSwipeDidFire {
    UITabBar *tabBar = self.tabBarController.tabBar;
    NSInteger index = [tabBar.items indexOfObject:tabBar.selectedItem];
    if (index > 0) {
        self.tabBarController.selectedIndex = index - 1;
    } else {
        return;
    }
}
0

try this code so you can swipe the tab bar

- (void)viewDidLoad {
    [super viewDidLoad];
    UISwipeGestureRecognizer *leftToRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftToRightSwipeDidFire)];
    leftToRightGesture.direction = UISwipeGestureRecognizerDirectionRight;
    [self.tabBarController.tabBar addGestureRecognizer:leftToRightGesture];

    UISwipeGestureRecognizer *rightToLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightToLeftSwipeDidFire)];
    rightToLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.tabBarController.tabBar addGestureRecognizer:rightToLeftGesture];
}


- (void)leftToRightSwipeDidFire {
    UITabBar *tabBar = self.tabBarController.tabBar;
    NSInteger index = [tabBar.items indexOfObject:tabBar.selectedItem];
    if (index > 0) {
        self.tabBarController.selectedIndex = index - 1;
    } else {
        return;
    }
}
- (void)rightToLeftSwipeDidFire {
    UITabBar *tabBar = self.tabBarController.tabBar;
    NSInteger index = [tabBar.items indexOfObject:tabBar.selectedItem];
    if (index < tabBar.items.count - 1) {
        self.tabBarController.selectedIndex = index + 1;
    } else {
        return;
    }
}
Jigar
  • 1,801
  • 1
  • 14
  • 29