GestureRecognizer
을 빌드하여 오른쪽에서 왼쪽으로 UIView
을 드래그하려고합니다. 사용자가보기를 화면 절반으로 드래그하면보기가 자동으로 왼쪽 모서리로 드래그되어 삭제되지만 사용자가 화면 절반까지 드래그하지 않으면 화면 오른쪽 구석으로 돌아갑니다. 여기에 약간의 자습서 또는 다른 것이 있습니까? 감사UIView를 드래그하는 UIGestureRecognizer
편집 : Heres는 일부 코드, 자사의 UIImageView
하는 UIScrollView
안에, 내가 전체를 스크롤하거나 이미지를 그 안에 드래그해야합니다 내가 드래그하려고
_myScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.window.bounds.size.width, self.window.bounds.size.height)]; [_myScroll setContentSize:CGSizeMake(self.window.bounds.size.width , 1300)];
_tutorial = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.window.bounds.size.width, 1300)]; [_tutorial setImage:[UIImage imageNamed:@"Default"]];
_tutorial.contentMode = UIViewContentModeScaleAspectFit; [_myScroll addSubview:_tutorial];
_tutorial.userInteractionEnabled = YES;
UIPanGestureRecognizer * recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:_tutorial action:@selector(handlePan:)];
[_tutorial addGestureRecognizer:recognizer];
[self.window addSubview:_myScroll];
그리고 방법을 the UIImageView
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:_myScroll];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:_myScroll];
}
나는 귀하의 질문에 대답했지만 "보기를 끌 수는 있지만 올바른 위치로가는 방법을 모르겠다"와 같이 시도한 것에 대한 자세한 내용을 제공해야합니다 ... – rdurand
@ rdurand 예, UIPanGestureRecognizer를 사용하여 뷰를 끌 수는 있지만 위치를 감지하는 방법을 정확히 모르고 원하는 위치로 뷰를 보냅니다. 그리고 두 번째 문제는 뷰를 드래그하는 방법, 가로 방향에만 – darkman
일부 코드를 제공합니다. * 시도하지 않은 것을 시도해보십시오. – rdurand