2009-10-26 5 views
0

필자는 정렬이 필요없는 다소 까다로운 스크롤링 scenerio가 있습니다. 두 자식 하위 UIView 하위 클래스를 포함하는 단일 컨테이너보기 부모 UIScrollView가 있습니다. viewA와 viewB를 호출하십시오. UIScrollView가 가로로 스크롤/확대/축소되도록 제한되었습니다. ViewA와 ViewB는 수평 스트립으로 배치됩니다. viewA와 viewB의 범위는 scrollView의 범위를 초과하며 스크롤/확대/축소 중에 표시됩니다. 여태까지는 그런대로 잘됐다.UIScrollView 내에서 드래그 가능한 UIView 하위 클래스를 구현하려면 어떻게해야합니까?

다음은 다소 까다로운 부분입니다. 가로로뿐만 아니라 세로로 뷰 B를 드래그 할 수 있어야합니다. 내 viewB를 자체 scrollView에 중첩하지 않는 것이 좋습니다.

제 질문은 올바른 viewViewB에 대한 간단한 세로 스크롤링을 구현하는 동안 올바른 방법은 무엇입니까? 뷰 B의 변환 행렬을 조작하는 뷰 B에서 begin/moved/ended/cancelled와 같은 명확한 4 가지 터치 시퀀스 메서드를 구현하면됩니까? 사전에

감사합니다.

건배, 더그

+0

왜 ViewB가 자신있는 ScrollView에있을 싶지 않아? – NSResponder

+0

단어 : 복잡성. scrollView 내 요구에 과잉이다. – dugla

답변

0

다음과 같이 음, 당신의 주어진 시나리오에 관하여, 나는이 문제를 해결합니다 : 모든

첫째는 nessecary 기능을 포함하여 UIView의-서브 클래스 생성이 하나는 드래그를 수신 -행위. 이것은 드래그 가능한 동안 UIScrollView의 스크롤을 해제해야합니다. 헤더 :

#import <UIKit/UIKit.h>; 

@interface ViewB : UIView 
{ 
} 

@end 

구현 :

#import "ViewB.h" 

@implementation DragView 
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    self.alpha = 0.5; 
    ((UIScrollView*)self.superview.superview).scrollEnabled = NO; 
} 

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint loc = [touch locationInView:self.superview]; 
    self.center = loc; 
} 

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    self.alpha = 1.0; 
    ((UIScrollView*)self.superview.superview).scrollEnabled = YES; 
} 

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    self.alpha = 1.0; 
    ((UIScrollView*)self.superview.superview).scrollEnabled = YES; 
} 

// Further methods... 

@end 
관련 문제