iOS UIScrollView,用 2 根手指平移进行分页,用一根手指平移进行“手指指针”操作

发布于 2024-11-06 20:23:25 字数 465 浏览 0 评论 0原文

我花了相当多的时间来弄清楚如何实现我想做的事情,但还没有找到合适的解决方案。我有一个 UIScrollView,其中我将 panGestureRecognizer 从一根手指识别更改为两根手指识别,因此分页仅在使用两根手指时才起作用。现在我想添加一个额外的 panGestureRecognizer,如果我用一根手指平移,它会显示一个课程器。我尝试通过向 UIScrollView 添加一个额外的 panGestureRecognizer 来实现这一点,但应用程序立即崩溃。因此,我想到添加一个透明的子视图,位于 UIScrollView 上方,并使用 resgin firstResponder 之类的东西将两个手指手势委托给 UIScrollView。我还想过覆盖 UIScrollView 的 pangestureRecognizer 并让它在我的“手指指针”(一个位于我现在触摸屏幕的中心的小点)所在的位置添加一个子视图。我完全不知道我应该走什么路以及如何实施。非常感谢您的帮助!多谢!

蒂莫

I spend quite some time to figure out how to achieve what I want to do but didn't find a proper solution for it, yet. I have a UIScrollView where I changed the panGestureRecognizer from one to two finger recognition so the paging only works when two fingers are used. Now I want to add an additional panGestureRecognizer that shows a courser if I'm panning with one finger. I tried that by just adding an additional panGestureRecognizer to the UIScrollView but then the app crashes immediately. So I thought of adding a subview that is transparent and positioned above the UIScrollView and that I delegate the two finger gestures to the UIScrollView with something like resgin firstResponder. I also thought of overwriting the pangestureRecognizer of the UIScrollView and let it add a Subview where my "fingerpointer"(a little point that is centered where I'm touching the screen right now) is located. I'm totally clueless what way I should go and how to implement it. Your help is greatly appreciated! Thanks a lot!

Timo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一桥轻雨一伞开 2024-11-13 20:23:25

好的,这是第二次编辑我的回复。这可能对你有用。

如果您扩展 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
   }
}

Ok, this is the second time editing my response. This might do the trick for you.

If you extend UIScrollView you can override these methods in this way:

//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
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文