2016-08-17 3 views
0

Здесь у меня три вида слева, середина, справа, поэтому я хотел добавить функциональность салфетки, я пробовал следующий путь, но все еще не могу ее сделать. Как я могу это сделать.Добавление жестов салфетки, Невозможно пронести

КОД:

- (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]; 

    } 

Переход правого

-(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]; 


    } 

перехода для левого

-(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

, что вы хотите достичь, я думаю, вы должны используйте либо контроллер просмотра страницы, либо поместите 3 вида в scrollview с включенным пейджингом. сделайте ширину scrollview настолько большой, насколько вы хотите, согласно вашему требованию. –

+0

Эти методы не звонят ни разу? – Nilesh

+0

@NileshJha, когда я добавил точку останова и запустил программу, появится вид, который вызывается, и когда я прокручиваю левую точку останова, выходим влево и контролируем левый и правый, но все же отображается средняя метка, она должна показывать левую метку, когда i проведите пальцем влево, когда я добавил ярлык на соответствующие экраны – virat

ответ

0

Заменить этот

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

К этому

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

Это сделает ваш контроллер представления появляются. Но поскольку у контроллера левого или правого вида нет указателя распознавания жестов, поэтому вы не вернетесь с этого контроллера. Для этого вы сделаете их похожими на салфетки.

+0

ya это работает, но мне нужна анимация, как будто она должна отображаться в соответствии с салфеткой, но она отображает левый viewController снизу, но он должен появиться слева – virat

+0

@ virat вы добавили UINavigationControl ler или не ? –

+0

@iRaju no i не добавил – virat

0

У меня есть решение brother.I попробовал образец проекта для вашего вопроса. Теперь я получил решение.

Сначала я установил ViewControllers в раскадровке. Посмотрите на раскадровку, в которой снимок экрана имеет UINavigationController, ViewController, LeftViewController, RightViewController.

enter image description here

Тогда в 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 
Смежные вопросы