我正在尝试构建一个
编辑:这里是一些代码,它是一个
GestureRecognizer
,以从右向左拖动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];
}