我試圖建立一個GestureRecognizer
拖動一個UIView
從右到左。如果用戶將視圖拖動到屏幕的一半,視圖將自動拖動到左角以放棄它,但如果用戶不拖動到屏幕的一半,它將返回到屏幕右側的角落。 這裏很少迷失,任何教程或什麼? 感謝UIGestureRecognizer拖動UIView
編輯:繼承人一些代碼,它是一個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];
而且方法我嘗試拖動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