これは単純なはずのようですが、そうではないようです。
私はストーリーボードを使用しており、最初のビューコントローラーはとして定義されていLogbookFirstViewController
ます。
このコントローラーの内容は、の中にありUIControl
ます。そうすれば、タップを検出できます。
ただし、ユーザーが画面をスワイプし始めた時期を簡単に判断する方法はわかりません。私がやりたいのは、x座標のタッチを取得することだけです。基本的にそれを追跡します。
UIPanGestureRecognizer
私は内側を落とし、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
私は何が欠けていますか?よろしくお願いします。