iOS的UIScrollView有2个手指锅用于分页和一个手指锅用于“手指指针”
问题描述:
我花了相当长的时间来弄清楚如何实现我想要做的事情,但是还没有找到合适的解决方案。我有一个UIScrollView,我将panGestureRecognizer从一个手指识别到两个手指识别,因此只有在使用两个手指时才能进行分页。现在我想添加一个额外的panGestureRecognizer,如果我用一根手指平移,它将显示一个courser。我试图通过添加一个额外的panGestureRecognizer到UIScrollView,但随后应用程序立即崩溃。所以我想添加一个透明且位于UIScrollView之上的子视图,并且我将这两个手指手势委托给UIScrollView,像resgin firstResponder。我还想过覆盖UIScrollView的pangestureRecognizer,并让它添加一个子视图,其中我的“指针”(位于我正在触摸屏幕的中心点)位于此处。我完全无能为力,应该怎样去实施它。非常感谢您的帮助!非常感谢!iOS的UIScrollView有2个手指锅用于分页和一个手指锅用于“手指指针”
Timo
答
好的,这是第二次编辑我的回应。这可能对你有用。
如果扩展的UIScrollView可以覆盖这样这些方法:
//In your h file
BOOL cursorShown;
//In your m file
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if([touches count] == 1)
{
cursorShown = YES;
CGPoint touchLocation = [[touches anyObject] locationInView:self.superview]
//Add your cursor to the parent view here and set its location to touchLocation
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if(cursorShown == YES)
{
CGPoint touchLocation = [[touches anyObject] locationInView:self.superview]
//Move your cursors location to touchLocation
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(cursorShown == YES)
{
cursorShown = NO;
//Destroy your cursor
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
if(cursorShown == YES)
{
cursorShown = NO;
//Destroy your cursor
}
}