2012-07-02 1 views
2

모두 카메라슬라이드 식/팬 -보기

enter image description here

내가 비슷한 무언가를 원하는의 잠금 화면에서 드래그보기를 알고있다. 내 레이아웃이 서브 뷰가 바닥에서 드래그해야하고 cetrain 높이에 열린 을 유지해야이

enter image description here

  • 것 같습니다. 위로 스 와이프하면 하위 뷰를 드래그하지만 최대 위치하기 전에 중지 할 때
  • 또한 빠른 그 자체를 를 열어야합니다, 그것은 위로 밀어 내려하면 슬라이드와 다음도
  • 그 자체로 내려 가서 sould
  • 아래로 슬라이딩한다 두드리기가 자체적으로 위/아래로 움직일 때

이 동작은 잠금 화면 (높이 정지 제외)에서 매우 잘 볼 수 있습니다. 나는 UIPanGestureRecognizer과 같은 다른 것을 시도한 다음 최대 값을 설정했지만 슬라이드 할 수는 없습니다.

UIKit에 미리 패키징 된 항목이 있거나 직접 처리해야 할 항목이 있습니다. 그렇지 않다면,이 행동에 대한 좋은 방법은 무엇입니까?

+0

안녕하세요! 이것은 내가 찾고 정확히입니다. 는이 동작을 구현하는 방법을 발견 했습니까? –

+0

을 @DmitryZhukov 전혀 미안 . 아무것도 못 찾았 어. 뭔가 찾으면 알려줘! – choise

답변

5

다음은 계획입니다. UIView를 하위 클래스로 분류합니다. 몇 가지 속성을 추가하고 몇 가지 메서드를 재정의 할 것입니다. 아이디어는 당신이 터치로 터치를 지시하도록합니다 .Began과 touchesMoved. 손가락이 손을 떼면 Ended는보기를 적절한 휴식 위치로 움직입니다. 내가 제공하는 코드 샘플에서는 완전히 확장되거나 완전히 철회되지만 원하는 경우 언제든지 철회 할 수 있습니다.

약간의 관성이 적용되는 것처럼 들리는군요. 조금 더 복잡합니다. 추가 애니메이션을 직접 추가해야하기 때문입니다. 그러나 올바른 애니메이션을 연결하기 만하면됩니다 (예 : 타이밍 기능을 사용하여 종료 지점을지나 애니메이션으로 다시 가져와야 함). 그것은 사용자가 이동을 마친 후에 시작됩니다. 당신이 공상을하고 싶다면, 당신은 스 와이프의 속도를 추적하고이 속도/운동량을 기반으로 애니메이션을 발사합니다.

다음은 서랍에 애니메이션 효과를 적용하는 데 도움이되는 코드 샘플입니다. 그것은 당신이 묘사 한 공상을 가지고 있지는 않지만, 그러한 행동을 어떻게 그리고 어디에서 도입 할 것인지를 결정할 근거를 제공해야합니다.

"현재 위치", 원점, 천장 (뷰가 위로 드래그를 중단해야하는 지점 또는 "밖으로"있는 지점) 및 바닥 최대 값은 Y 오프셋, 또는은) 아래에 가지 않을 좌표입니다.

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [touches anyObject]; 
    CGPoint startPt = [touch locationInView:self]; 
    self.currentPoint = startPt; 

} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

    CGPoint activePoint = [[touches anyObject] locationInView:self]; 

    //new position 
    CGPoint newPoint = CGPointMake(self.center.x, 
            self.center.y + (activePoint.y - currentPoint.y)); 

    if (newPoint.y > self.draggingFloor) { 
     //too low 
     newPoint.y = self.draggingFloor; 

    } else if (newPoint.y < self.draggingCeiling) { 
     //too high 
     newPoint.y = self.draggingCeiling; 
    } 

    self.center = newPoint; 

} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

    //The user isn't touching. Now we can adjust to drawer to a "better" position. 
    //The 150f here is going to depend on how far the view should be dragged before it opens. 
    CGFloat median = pullDrawerYOrigin + 150.0f; 
    CGFloat position = self.center.y; 

    if (position <= median) { 
     //We're closer to open than closed. So open all the way. 
     [self animateDrawerToPositionYesForOpen:YES]; 
    } 

    else if (position >= median) { 
     //close 
     [self animateDrawerToPositionYesForOpen:NO]; 
    } 


} 

- (CGFloat) draggingFloor { 

    //Don't drag any lower than this. 
    if (!__draggingFloor) { 
     __draggingFloor = pullDrawerYOrigin + (self.bounds.size.height *.5); 
    } 

    return __draggingFloor; 
} 

- (CGFloat) draggingCeiling { 

    //Don't drag any higher than this. 
    if (!__draggingCeiling) { 
     __draggingCeiling = self.superview.bounds.size.height + (self.bounds.size.height * .05); 
    } 

    return __draggingCeiling; 

} 
- (void) animateDrawerToPositionYesForOpen:(BOOL)position { 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationDuration:.2]; 

    CGPoint myCenter = self.center; 

    if (position == YES) { 
     myCenter.y = self.draggingCeiling; 
    } 

    else if (position == NO) { 
     myCenter.y = self.draggingFloor; 
    } 

    self.center = myCenter; 

    [UIView commitAnimations]; 

}