看起来这应该很简单,但显然并非如此。
我正在使用 Storyboard,我的第一个视图控制器定义为LogbookFirstViewController
.
此控制器的内容位于UIControl
. 这样我就可以检测到水龙头。
但是,我看不到确定用户何时开始在屏幕上滑动的简单方法。我想要做的就是触摸 x 坐标。基本上跟踪它。
我掉了一个UIPanGestureRecognizer
inside LogbookFirstViewController
,并附上了它的出口:
在.h
@property (assign) IBOutlet UIGestureRecognizer *gestureRecognizer;
当然,我然后合成它并设置委托:
在.m
[gestureRecognizer setDelegate:self];
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touchLoc = [touches anyObject];
CGPoint beginCenter = self.view.center;
CGPoint touchPoint = [touchLoc locationInView:self.view];
deltaX = touchPoint.x - beginCenter.x;
deltaY = touchPoint.y - beginCenter.y;
NSLog(@"X = %f & Y = %f", deltaX, deltaY);
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
// Set the correct center when touched
touchPoint.x -= deltaX;
touchPoint.y -= deltaY;
self.view.center = touchPoint;
}
但是,这无济于事。它甚至检测不到-(void)touchesBegan
我错过了什么?先谢谢了。