2011-05-04 7 views
0

Iphone으로 응용 프로그램을 개발하려고합니다. 하지만 나는 새로운 꿀벌이에요 그래서 나는 많은 문제가 있어요.제스처가있는 뷰를 스 와이프

내 응용 프로그램에는 기본보기가 있으며 기본보기에는 이름이 flashcard 인 다른 작은보기가 있습니다.

아이폰의 사진처럼 스 와이프 (또는 슬라이딩) 기능을 추가하고 싶습니다. 예를 들어 사용자가 내부보기의 중심이 기본보기의 경계에 도달 할 때까지보기를하면 두 가지 가능성이 있습니다. 1- 도달하기 전에 사용자가 스 와이프를 완료하면 내부보기가 원래 위치로 돌아갑니다. 2- 사용자가 스 와이프를 중지하지 않으면 내부보기가 스 와이프 방향에서 화면으로 나가서 화면을 반대 방향에서 되돌립니다.

그래서 내가

UIPanGestureRecognizer *panFlashCard = [[UIPanGestureRecognizer alloc] 
             initWithTarget:self action:@selector(handlePanFlashCard:)]; 

[flashcard addGestureRecognizer:panFlashCard]; 
[panFlashCard release]; 

아래 handPanFlashCard 액션처럼의 viewDidLoad에서 UIPanGestureRecognizer을 선언

UIView *piece = [recognizer view]; 
    CGPoint center = piece.center; 
    CGFloat x = 160; // the original x axis of inner view 

    if ([recognizer state] == UIGestureRecognizerStateChanged) { 
     CGPoint translation = [recognizer translationInView:piece ]; 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.55]; 
     [piece setCenter:CGPointMake(piece.center.x + translation.x, center.y)]; 
     [UIView commitAnimations]; 
     CGFloat totalX; 
     totalX= x + translation.x; 
     if(translation.x <0) 
     {    
      if (totalX <= 0) 
      { 
       [self showNextCard]; 
      } 
      else 
      { 
       [UIView beginAnimations:nil context:NULL]; 
          [UIView setAnimationDuration:0.55]; 
          [piece setCenter:CGPointMake(self.view.center.x, center.y)]; 
          [UIView commitAnimations]; 
      } 
     } 
     else 
     { 
      if (totalX >= self.view.bounds.size.width) 
      { 
       [self showPreviousCard]; 
      } 
      else 
      { 
       [UIView beginAnimations:nil context:NULL]; 
       [UIView setAnimationDuration:0.55]; 
       [piece setCenter:CGPointMake(self.view.center.x, center.y)]; 
       [UIView commitAnimations]; 
      } 
     } 
    } 

showNextCard 액션 :

[flashcard setCenter:CGPointMake(self.view.bounds.size.width + flashcard.bounds.size.width, flashcard.center.y)]; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.55]; 
    [flashcard setCenter:CGPointMake(self.view.center.x, flashcard.center.y)]; 
    [UIView commitAnimations]; 

showPreviousCard 액션 :

[flashcard setCenter:CGPointMake(0 - flashcard.bounds.size.width, flashcard.center.y)]; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.55]; 
    [flashcard setCenter:CGPointMake(self.view.center.x, flashcard.center.y)]; 
    [UIView commitAnimations]; 

이 응용 프로그램을 실행하면 성공적으로 빌드되고 실행되지만 애니메이션에는 문제가 있으며 일부 프레임 실수는 생각합니다.

이 코드를 수정하고 스 와이프 중에 유창한 애니메이션을 실행하도록 도와주세요.

답변

0

내가 무엇을하려하는지 이해했다면이 기능을 내장 된 컨트롤을 사용할 수 있습니다. UIScrollView 클래스의 pagingEnabled 속성을 살펴보십시오. 또한 도움이 될만한 PhotoScroller라는 샘플 프로젝트가 있습니다.

http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html

+0

나는 샘플 코드를 볼 것이다; 그러나 나는이 컨트롤이 나를 위해 어울리는 지 확신하지 못한다. 내부보기에 일부 레이블을 추가하고 모든 전체 스 와이프 (NextCard 또는 PreviousCard 동작) sqlite 데이터베이스에서 새 데이터를 가져 오려면 –

+0

원하는 모든보기를 스크롤보기에 추가 할 수 있습니다. 그래서 당신은 각 카드가 여러 라벨을 지닌 UIView가되는 카드 배열을 가질 수 있습니다. 그러면 어떤 카드가 보여지고 있는지 파악하고로드를 수행하면됩니다. – jaminguy

관련 문제