2014-04-18 2 views
0

부드럽게 스 와이프 애니메이션을하고 싶습니다. 사용자가 오른쪽 또는 왼쪽 테두리에서만 페이지를 스 와이프하면 해당 스 와이프 만 가능할 수 있습니다. 페이지 스 와이프의 중간 부분은 가능하지 않아야합니다. 두 스 와이프 모두 왼쪽에서 오른쪽, 오른쪽에서 왼쪽으로 가능해야합니다.ios에서 부드러운 스 와이프 애니메이션을 수행하는 방법

많은 스 와이프 애니메이션 샘플 코드 또는 데모 코드를 사용해 보았습니다. 하지만 내가 원하는 것은 아닙니다. 이 애니메이션을 좋아해요 https://itunes.apple.com/in/app/clear-tasks-to-do-list/id493136154?mt=8

이 응용 프로그램에서 우리가 오른쪽 테두리를 만지면 부드럽게 스 와이프됩니다.이 애니메이션을 수행하도록 안내해주십시오. 미리 감사드립니다.

+0

이 도움이

희망은 ... ... 당신이 좌우 및 상하 슬쩍 슬쩍 제공 할 것입니다. –

답변

2

늦게 답장을 보내 드려 죄송합니다. 이 질문을 보았습니다.

당신은 당신의 슬쩍 작업의 가장자리에서 발생 기본보기 (왼쪽 및 오른쪽)이 맨 끝에서 파단을 만든 다음 (30)의 폭 또는 40

enter image description here

을 부여하려면

나는 다른 관점에서 popin을 왼쪽에서 오른쪽으로 믿는다. 따라서 inorder를 사용하면 메인 뷰 상단에 2 개의 뷰를 추가해야합니다. 이제 왼쪽보기의 경우 주보기에 연결하는 오른쪽 수평 공간 제약 조건을 주보기의 (-1) x 너비보다 작은 값으로 설정하십시오. 우측 뷰의 뷰 모두

X stands for a value greater than or equal to the mainview's width

X가 약자 메인 뷰 외부 지도록 오른쪽 horizondal 공간 제약은, 메인 뷰의 폭보다도 큰 값으로 메인 뷰에 연결 설정 내용 메인 뷰의 너비보다 크거나 같은 값

두 개의 NSLayoutConstraint 변수를이 두 값을 유지하는 IBOutlet으로 추가하십시오.

NSLayoutConstraint *leftViewHorizondalRightPadding; 
NSLayoutConstraint *rightViewHorizondalRightPadding; 

이제 이러한 하위 뷰 (주황색 표시)에 UISwipeGestures를 추가하십시오. 오른쪽에서 왼쪽으로 왼쪽에서 오른쪽으로

UISwipeGestureRecognizer *leftToRightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 
    [leftToRightSwipe setDirection:UISwipeGestureRecognizerDirectionRight]; 
    [self.leftSubview addGestureRecognizer:leftToRightSwipe]; 

UISwipeGestureRecognizer *rightToLeftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 
    [rightToLeftSwipe setDirection:UISwipeGestureRecognizerDirectionLeft]; 
    [self.rightSubview addGestureRecognizer:rightToLeftSwipe]; 

///Now in the swipe handler distinguish the swipe actions 
-(void)handleSwipe:(UISwipeGestureRecognizer *)recognizer { 
    NSLog(@"Swipe received."); 
    if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) { 
    //It's leftToRight 
     leftViewHorizondalRightPadding.constant = 0; 
     [UIView animateWithDuration:1 
      animations:^{ 
      [self.view layoutIfNeeded]; 
     }]; 

    } 
    else { 
    //It's rightToLeft 
     rightViewHorizondalRightPadding.constant = 0; 
     [UIView animateWithDuration:1 
      animations:^{ 
      [self.view layoutIfNeeded]; 
     }]; 

    } 
} 

}

이 슬쩍 애니메이션을 만들 것입니다.당신은 그것을 위해 슬쩍 제스처를 사용할 수 있습니다

0

두 개의 제스처 인식기를 만든 후에는 해당 대리인을 설정해야합니다.

UISwipeGestureRecognizer *_swipeLeft; 
UISwipeGestureRecognizer *_swipeRight; 
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { 
    static const CGFloat borderWidth = 50.0f; 
    if(gestureRecognizer == _swipeLeft) { 
     return [gestureRecognizer locationInView:self].x > self.frame.size.width - borderWidth; 
    } 
    else if(gestureRecognizer == _swipeRight) { 
     return [gestureRecognizer locationInView:self].x < borderWidth; 
    } 
    return YES; 
} 

당신은 아마보다는 슬쩍 제스처를 팬 동작 또는 길게 누르기 제스처 인식기를 사용해야합니다 드래그/부드러운 스 와이프를위한 점에 유의 마십시오 : 그런 다음이 위임 방법을 사용합니다. 긴 보도 자료가 시작하기에 약간의 시간이 걸린다는 점을 제외하고는 매우 유사합니다 (이는 설정 가능합니다). 이들을 사용하는 경우에도 동일한 위임 방법을 사용할 수 있습니다. 또는 제스처 대상 메서드에서 모든 코드를 간단하게 수행 할 수 있습니다. iOS7에에서

CGPoint gestureStartPoint; 
- (void)dragFromBoreder:(UIGestureRecognizer *)sender { 
    static const CGFloat borderWidth = 50.0f; 
    switch (sender.state) { 
     case UIGestureRecognizerStateBegan: { 
      CGPoint location = [sender locationInView:self]; 
      if(location.x > borderWidth || location.x < self.frame.size.width-borderWidth) { 
       //break the gesture 
       sender.enabled = NO; 
       sender.enabled = YES; 
      } 
      else { 
       gestureStartPoint = location; 
      } 
      break; 
     } 
     case UIGestureRecognizerStateChanged: { 
      CGPoint location = [sender locationInView:self]; 
      CGFloat deltaX = location.x - gestureStartPoint.x; 
      UIView *viewToMove; 
      CGPoint defaultCenter; 
      viewToMove.center = CGPointMake(defaultCenter.x+deltaX, defaultCenter.y); 
      break; 
     } 
     case UIGestureRecognizerStateEnded: 
     case UIGestureRecognizerStateCancelled: { 
      CGPoint location = [sender locationInView:self]; 
      CGFloat deltaX = location.x - gestureStartPoint.x; 
      /* 
      if(deltaX > someWidth) { 
       show the left view 
      } 
      else if(deltaX < -someWidth) { 
       show the right view 
      } 
      else { 
       put everything back the way it was 
      } 
      */ 
      break; 
     } 
     default: 
      break; 
    } 
} 
0

제스처 인식기 specifically for gestures beginning from the edge of the screen가이 같은 것을보십시오. 이걸 사용해야합니다.

현재의 애니메이션이 어떻게 보이는지 또는 어떻게하고 있는지에 대해 말하지 않았기 때문에 나는 "부드러운"문제를 해결할 수 없습니다. 그러나 뷰 위치를 직접 업데이트하는 연결된 것과 같은 팬 제스처는 스 와이프보다 사용자의 움직임을 훨씬 부드럽게 추적합니다.

+0

감사합니다. 확인하고 더 이상 도움이 필요하면 알려 줄 수 있습니다. – NSP

관련 문제