Assam AlZookery Assam AlZookery - 1 year ago 67
Objective-C Question

The user can either swipe or click the buttons to Navigate between view Controllers

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

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;


@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.


Answer Source

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 {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download