c2p*_*ing 3 cocoa cocoa-touch touchesbegan ios
我有以下问题.我正在使用一个UILongPressGestureRecognizer
UIView进入"切换模式".如果UIView
处于"切换模式",则用户可以在屏幕上拖动UIView.为了在屏幕上拖动UIView我正在使用方法touchesBegan
,touchesMoved
和touchesEnded
.
它工作,但是:我必须举起手指才能拖动它,因为该touchesBegan
方法已被调用,因此不会再次调用,因此我无法拖动UIView
屏幕.
触发touchesBegan
后是否有任何方法可以手动调用UILongPressGestureRecognizer
(UILongPressGestureRecognizer
更改BOOL值,touchesBegan
仅当此BOOL设置为YES时才有效).
Rob*_*Rob 10
UILongPressGestureRecognizer
是一个连续的手势识别器,所以,而不是诉诸touchesMoved
或UIPanGestureRecognizer
,只是检查UIGestureRecognizerStateChanged
,例如:
- (void)viewDidLoad
{
[super viewDidLoad];
UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[self.view addGestureRecognizer:gesture];
}
- (void)handleGesture:(UILongPressGestureRecognizer *)gesture
{
CGPoint location = [gesture locationInView:gesture.view];
if (gesture.state == UIGestureRecognizerStateBegan)
{
// user held down their finger on the screen
// gesture started, entering the "toggle mode"
}
else if (gesture.state == UIGestureRecognizerStateChanged)
{
// user did not lift finger, but now proceeded to move finger
// do here whatever you wanted to do in the touchesMoved
}
else if (gesture.state == UIGestureRecognizerStateEnded)
{
// user lifted their finger
// all done, leaving the "toggle mode"
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3734 次 |
最近记录: |