我喜欢将UILongPressGestureRecognizer与UIPanGestureRecognizer结合使用.
UIPanGestureRecognizer应该从长按开始.有一个简单的方法吗?还是我真的要写自己的手势识别器?
我不喜欢在主屏幕上.你按下一个图标,一段时间后图标开始摇晃.之后我没有从屏幕上松开手指,我可以开始拖动手指下的图标.
cocoa-touch objective-c uigesturerecognizer uipangesturerecognizer uilongpressgesturerecogni
我想在这个视图中移动一些UIView按钮.我可以这样做:
- (void)viewDidLoad
{
[button addTarget:self action:@selector(dragBegan:withEvent:) forControlEvents: UIControlEventTouchDown];
[button addTarget:self action:@selector(dragMoving:withEvent:) forControlEvents: UIControlEventTouchDragInside];
[button addTarget:self action:@selector(dragEnded:withEvent:) forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
}
Run Code Online (Sandbox Code Playgroud)
.
- (void)dragBegan:(UIControl *)c withEvent:ev {
UITouch *touch = [[ev allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
}
- (void)dragMoving:(UIControl *)c withEvent:ev {
UITouch *touch = [[ev allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
//This is moving view to touchPoint
SimpleView.center = touchPoint;
}
- (void)dragEnded:(UIControl *)c withEvent:ev {
}
Run Code Online (Sandbox Code Playgroud)
我怎么能只在那时移动它,如果我长按该按钮?