2016-08-17 6 views
0

여기 왼쪽, 가운데, 오른쪽 세 가지 뷰가 있으므로 스 와이프 기능을 추가하고 싶습니다. 다음 방법을 시도했지만 아직 만들 수 없습니다. 어떻게 할 수 있습니까?스 와이프 제스처 추가 스 와이프 할 수 없습니다.

CODE : 왼쪽

-(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 너비를 확인하십시오. –

+0

그 방법은 한 번도 호출하지 않습니까? – Nilesh

+0

@ NileshJha 중단 점을 추가하고 프로그램을 실행하면 뷰가 호출 될 것입니다. 왼쪽으로 스 와이프하면 중단 점이 leftViewController로 이동하지만 오른쪽으로는 여전히 중간 레이블이 표시됩니다. 왼쪽 레이블이 표시되어야합니다. 각 화면에 레이블을 추가 할 때 왼쪽으로 스 와이프합니다. – virat

답변

0

바로

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

    } 

전환이

[self.navigationController pushViewController:videoScreen animated:YES]; 
교체 이

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

으로

그것은 당신의 뷰 컨트롤러를 표시 할 것입니다. 하지만 왼쪽 또는 오른쪽보기 컨트롤러에는 제스처 인식기가 없으므로 해당보기 컨트롤러에서 돌아 오지 않습니다. 이렇게하면 스 와이프 할 수 있습니다.

+0

나중에이 작동하지만 그것은 스 와이프에 따라 표시해야합니다 같은 애니메이션 싶었지만 왼쪽에서 viewController 왼쪽에서 제시합니다하지만 – virat

+0

@virat UINavigationControl ler 또는 않았다 추가 한 않았다 ? –

+0

@iRaju 아니 내가 추가하지 않았다 – virat

0

나는 솔루션 형제가 있습니다. 나는 당신의 질문에 샘플 프로젝트를 시도했습니다. 이제 해결책을 얻었습니다.

먼저 storyboard.SeeUnavigationController, ViewController, LeftViewController, RightViewController가있는 스토리 보드에서 ViewController를 아래 스크린 샷으로 설정하십시오. RightViewController.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]; 
} 

ViewController.m

enter image description here

그런 다음

#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