Objective c 使用UIGestureRecognitor在手指移动时获取坐标?
我正在尝试制作一个滑块,图像用手指从左向右滑动。我想使用UIgestureRecognitor。我怎样才能做到这一点,每次手指移动时,都会记录手指的坐标?你可以试试这样的方法Objective c 使用UIGestureRecognitor在手指移动时获取坐标?,objective-c,slider,uigesturerecognizer,jailbreak,user-interaction,Objective C,Slider,Uigesturerecognizer,Jailbreak,User Interaction,我正在尝试制作一个滑块,图像用手指从左向右滑动。我想使用UIgestureRecognitor。我怎样才能做到这一点,每次手指移动时,都会记录手指的坐标?你可以试试这样的方法 -(void)viewDidLoad; { [super viewDidLoad]; UIPanGestureRecognizer* pgr = [[UIPanGestureRecognizer alloc] initWithTar
-(void)viewDidLoad;
{
[super viewDidLoad];
UIPanGestureRecognizer* pgr = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(handlePan:)];
[self.panningView addGestureRecognizer:pgr];
}
-(void)handlePan:(UIPanGestureRecognizer*)pgr;
{
if (pgr.state == UIGestureRecognizerStateChanged) {
CGPoint center = pgr.view.center;
imageView.center = center;
}
}
另一种方法是使用
[pgr locationInView:self.view]
,它将为您提供每个触摸位置的CGPoint
。对于滑块,最有可能只使用x值。