2016-08-17 1 views
0

Ici, j'ai trois vues, l'un est à gauche, au milieu, à droite, donc je voulais ajouter la fonctionnalité de balayage que j'ai essayé de la manière suivante mais toujours incapable de le faire.Ajouter un geste de balayage, Impossible de glisser

CODE:

- (void)viewDidLoad { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view, typically from a nib. 
    } 


    - (void)viewWillAppear:(BOOL)animated{ 
     [super viewWillAppear:animated]; 

     UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerRight:)]; 
     [gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)]; 
     [self.view addGestureRecognizer:gestureRecognizer]; 
     //Left Swipe 

     UISwipeGestureRecognizer *gestureRecognizer2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerLeft:)]; 
     [gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)]; 
     [self.view addGestureRecognizer:gestureRecognizer2]; 

    } 

Transition pour le droit

-(void)swipeHandlerRight:(id)sender 
    { 

     RightViewController *videoScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"]; 


CATransition* transition = [CATransition animation]; 
    transition.duration = 0; 
    transition.type = kCATransitionFromRight; 
    // transition.subtype = kCATransitionFromRight; 
    [self.view.window.layer addAnimation:transition forKey:kCATransition]; 
    [self presentViewController:videoScreen animated:NO completion:nil]; 


    } 

Transition pour Left

-(void)swipeHandlerLeft:(id)sender 
    { 
     LeftViewController *videoScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"]; 
     CATransition* transition = [CATransition animation]; 
    transition.duration = 0; 
    transition.type = kCATransitionFromLeft; 
    // transition.subtype = kCATransitionFromRight; 
    [self.view.window.layer addAnimation:transition forKey:kCATransition]; 


    } 
+0

ce que vous voulez réaliser, je pense que vous devriez utilisez un contrôleur de vue de page ou placez 3 vues dans un scrollview avec pagination activée. faire la largeur scrollview autant que grand vous voulez selon votre condition. –

+0

Ces méthodes n'appellent-elles même pas une seule fois? – Nilesh

+0

@NileshJha quand j'ai ajouté un point d'arrêt et exécutez le programme la vue apparaîtra appelée et quand je balayerai à gauche le point d'arrêt va à leftViewController et même pour droit mais toujours l'étiquette du milieu est montrée là, elle devrait montrer l'étiquette gauche quand je Balayez vers la gauche pendant que j'ajoute l'étiquette sur les écrans respectifs – virat

Répondre

0

Remplacer cette

[self.navigationController pushViewController:videoScreen animated:YES]; 

Par cette

[self presentViewController:videoScreen animated:YES completion:NULL]; 

Il fera de votre contrôleur de vue apparaît. Mais comme le contrôleur de vue de gauche ou de droite n'a pas de reconnaissance de gestes, vous ne pourrez pas revenir à partir de ce contrôleur de vue. Pour cela, vous devez les faire glisser.

+0

ya cela fonctionne mais je voulais que l'animation comme il devrait apparaître en fonction de glisser mais il présente le viewController gauche à partir du bas, mais il devrait venir de gauche – virat

+0

@virat avez-vous ajouté UINavigationControl ler ou non ? –

+0

@iRaju non je n'ai pas ajouté – virat

0

J'ai obtenu la solution brother.I a essayé le projet d'échantillon pour votre question. Maintenant j'ai eu la solution.

D'abord, je place les ViewControllers dans le storyboard. Voir le storyboard qui a UINavigationController, ViewController, LeftViewController, RightViewController dans la capture d'écran ci-dessous.

enter image description here

Puis, en ViewController.m

#import "ViewController.h" 
#import "RightViewController.h" 
#import "LeftViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

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


- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    //swipe right 
    UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerRight:)]; 
    [gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)]; 
    [self.view addGestureRecognizer:gestureRecognizer]; 

    //swipe left 
    UISwipeGestureRecognizer *gestureRecognizer2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerLeft:)]; 
    [gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)]; 
    [self.view addGestureRecognizer:gestureRecognizer2]; 

} 

#pragma mark - swipe right function 
-(void)swipeHandlerRight:(id)sender 
{ 
    RightViewController *videoScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"]; 

    CATransition *animationRight = [CATransition animation]; 
    [animationRight setDuration:0]; 
    [animationRight setType:kCATransitionFromRight]; 
    [animationRight setSubtype:kCATransitionFromRight]; 
    [animationRight setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
    [self.view.window.layer addAnimation:animationRight forKey:kCATransition]; 
    [self presentViewController:videoScreen animated:NO completion:nil]; 
} 

#pragma mark - swipe left function 
-(void)swipeHandlerLeft:(id)sender 
{ 
    LeftViewController *videoScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"]; 
    CATransition *animationLeft = [CATransition animation]; 
    [animationLeft setDuration:0]; 
    [animationLeft setType:kCATransitionFromLeft]; 
    [animationLeft setSubtype:kCATransitionFromLeft]; 
    [animationLeft setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
    [self.view.window.layer addAnimation:animationLeft forKey:kCATransition]; 
    [self presentViewController:videoScreen animated:NO completion:nil]; 
} 

RightViewController.m

#import "RightViewController.h" 

@interface RightViewController() 

@end 

@implementation RightViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 

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

#pragma mark - Back to MiddleView 
- (IBAction)actionBackToMiddleView:(id)sender 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 
@end 

LeftViewController.m

#import "LeftViewController.h" 

@interface LeftViewController() 

@end 

@implementation LeftViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 

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

#pragma mark - Back to MiddleView 
- (IBAction)actionBackToMiddleViewFromLeftView:(id)sender 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 
@end