UIPanGestureRecognizer.maximumNumberOfTouches 在嵌套滚动视图中不受尊重?

发布于 2024-12-26 23:48:19 字数 710 浏览 0 评论 0原文

我有一个仅垂直滚动的根 UIScrollView ,此滚动视图代表锯齿状网格中的行。我已将此滚动视图的平移手势识别器配置为两次触摸,以满足所需的最小和最大触摸次数。

在这个滚动视图中,我有一个或多个仅水平滚动的 UIScrollView 实例,这些滚动视图各自代表我的锯齿状网格视图中的一行。我已经为所有这些滚动视图配置了平移手势识别器,最少一次触摸,最多两次触摸。

到目前为止,它有效,我得到了一个漂亮的锯齿状网格视图,我可以在行之间垂直滚动,并水平独立滚动每行。我故意将最小触摸次数设置为 2,以免担心如果我添加一个 UITableView 作为此锯齿状网格视图中任何单元格的子视图(cell == a由行和该行中的列定义的位置)。

使用 UITableView 作为单元格可以工作,表格视图可以按预期工作。但是用两根手指滚动也会在表视图内滚动,而不是在根滚动视图上滚动以在行之间垂直滚动。

我尝试将表格视图平移手势识别器配置为最多允许一次触摸,希望忽略两次手指触摸。这不起作用,表视图的平移手势识别器接缝的 maximumNumberOfTouches 属性将被忽略。

我可能做错了什么?

显示布局的屏幕截图以阐明我所做的事情:

I have a root UIScrollView that only scrolls vertically, this scrollview represents rows in my jagged grid. I have configured this scroll view's pan gesture recognizer for two touches for both minimum and maximum number of touches requires.

Inside this scrollview I have one or more UIScrollView instances that only scrolls horizontally, these scrollviews each represent a single row in my jagged grid view. I have configured the pan gesture recognizers for all of these scroll views for one touch minimum, and two touches maximum.

So far it works, I get a nice jagged grid view where I can scroll vertically between rows, and horizontally to scroll each row independently. I have intentionally set to minimum number of touches as 2, as not to inter fear with scrolling if I add fro example a UITableView as a subview for any of cell within this jagged grid view (cell == a position defined by a row and column in that row).

Using a UITableView as a cell works, the table view works as expected that is. But scrolling with two fingers also scrolls inside the table view, not at the root scroll view for vertically scrolling between rows.

I have tried configuring the table views pan gesture recognizer to allow a maximum of one touches, in hope that two finger touches would be ignored. This does not work, the maximumNumberOfTouches property of the table view's pan gesture recognizer seams to be ignored.

What could I have done wrong?

A screen shot displaying the layout to clarify what I have done:
Jagged Grid View

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

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

发布评论

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

评论(4

揽月 2025-01-02 23:48:19

多次滚动往往会变得棘手,我不确定,但我认为苹果并不鼓励这样做。即便如此,我仍然认为这是可能的。表视图上的垂直滚动可能与滚动视图垂直滚动或其他内容混合在一起。

尝试检查手势识别器的代表是否设置正确。
另一种解决方法是:
- 有一个带有按钮的滚动视图,您可以从中打开带有自定义控制器的弹出窗口(在其中插入您想要的任何内容)。
- 创建一个大的 UITableViewController 并将单元格的内容设置为滚动视图等。我认为您可以获得相同的结果。

我的建议是不要只坚持一种方法,因为可能还有其他更简单、更直观的方法。

Multiple scrolling tends to get tricky, and I don't for sure, but I think Apple does not encourage this. Even so, I still think it's possible. It may be that vertical scrolling on the table view gets mixed with the scroll view vertical scrolling or something else.

Try checking if the delegates for the gesture recognizers are correctly set.
Another way around this is:
- having a Scroll view with buttons, from which you can open popovers with custom controllers (insert there whatever you want).
- create a big UITableViewController and setting the cell's contents as scrollviews etc. I think you could get the same result.

My advice is not to get stuck on just one method, when there could be others more simpler and more intuitive.

述情 2025-01-02 23:48:19

滚动视图上的 TableView 通常不是一个好主意。当 TableView 接收到触摸时,即使不需要对其执行任何操作,它也不会将它们发送到其 superView。

您可能想尝试以下两件事中的任何一个:

  1. 在 TableView 中,您应该手动将触摸发送到 superView 并让它们适当地处理它们。我已经在我的一个副项目中看到了这种方法,但目前我无法发布它的示例。

  2. 第二件事可能更容易实现。由于 TableView 是 ScrollView 的子类,因此您可以调用这些 TableView 的delaysContentTouches。即使在该 TableView 上,此属性也会延迟触地,直到它可以确定滚动是否是意图,如 AppleDocs 中所写: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/occ/cl/UIScrollView

让我知道这两种方法是否适合您,我总体上对这个主题很好奇。

TableViews on Scroll views are generally not a great idea. When a TableView receives the touches, even if doesn't need to do anything with it, it won't send them to it's superView.

You might wanna try either of these 2 things:

  1. In your TableView you should send the touches to your superView manually and let them handle them appropriately. I've seen this method being used in one of my side-projects but I'm not able to post an example of it at this time.

  2. The second thing might be easier to implement. Since TableView is a subclass of ScrollView you can call upon the delaysContentTouches of those TableViews. This property will delay the touch-down even on that TableView until it can determine if scrolling is the intent, as is written in the AppleDocs: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/occ/cl/UIScrollView

Let me know if either of the 2 ways works for you, I'm quite curious about this subject generally.

穿越时光隧道 2025-01-02 23:48:19

但是,您是否应该尝试一些技巧而不是实现所有这些更改:

1) 默认情况下,创建视图时禁用 TableView 的滚动

2) 视图生成后,识别手势,无论是使用单次触摸还是多次触摸滚动,如果用户触摸子滚动视图。根据手势查看标签,即可启用 Tableview 的滚动。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
   //Get the tag of ScrollView 
   // Check for the Parent as well as Child SCrollview.
   // If its child, just enable the scrolling of tableView.
}

- (void)tapAction:(UIGestureRecognizer *)gestureRecognizer
{

//  CGPoint *poit = [Tile locationInView:gestureRecognizer.view];
/// [[[gestureRecognizers.view] objectAtIndex:0] removeFromSuperview];
//  imageContent = [[UIImageView alloc]initWithFrame:CGRec  tMake(0, 0, 200, 250)];
//  [imageContent setImage:[UIImage imageNamed:@"Default.png"]];

    NSLog(@"You tapped @ this :%d",gestureRecognizer.view.tag);
    //Regonize the gestures
}

可能有一些不必要的代码,因为您的问题没有代码片段。我尝试了一下;展示了一个技巧,如果这对你有用的话&解决问题。 ;)

But don't you try some tricks rather than implementing all such changes :

1) By Default, disable the scrolling of the TableView when the view is created.

2) Once the view gets generated, Recognize the gestures whether its Scrolling using single or multiple touches, if user touch the Child Scrollview.Look out the tag ,based on gestures, you can enable the Scrolling of Tableview.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
   //Get the tag of ScrollView 
   // Check for the Parent as well as Child SCrollview.
   // If its child, just enable the scrolling of tableView.
}

- (void)tapAction:(UIGestureRecognizer *)gestureRecognizer
{

//  CGPoint *poit = [Tile locationInView:gestureRecognizer.view];
/// [[[gestureRecognizers.view] objectAtIndex:0] removeFromSuperview];
//  imageContent = [[UIImageView alloc]initWithFrame:CGRec  tMake(0, 0, 200, 250)];
//  [imageContent setImage:[UIImage imageNamed:@"Default.png"]];

    NSLog(@"You tapped @ this :%d",gestureRecognizer.view.tag);
    //Regonize the gestures
}

There may be some unnecessary code since, there is no code snippet with your question.I gave a try & showed a trick if that could work for you & solve the problem. ;)

单调的奢华 2025-01-02 23:48:19

尝试 此链接并注意他们如何解决嵌套视图。

请记住处理多点触摸事件的最佳实践:

在处理事件(触摸事件和运动事件)时,您应该遵循一些推荐的技术和模式。

  • 始终实现事件取消方法。

在您的实现中,您应该将视图的状态恢复到当前多点触控序列之前的状态,从而释放为处理事件而设置的任何瞬态资源。如果您不实现取消方法,您的视图可能会处于不一致的状态。在某些情况下,另一个视图可能会收到取消消息。

  • 如果您在 UIView、UIViewController 或(极少数情况下)UIResponder 的子类中处理事件,

    • 您应该实现所有事件处理方法(即使它是空实现)。

    • 不要调用方法的超类实现。

  • 如果您在任何其他 UIKit 响应程序类的子类中处理事件,

    • 您不必实现所有事件处理方法。

    • 但是在您实现的方法中,请务必调用超类实现。例如,

[super TouchesBegan:theTouches withEvent:theEvent];

  • 不要将事件转发给 UIKit 框架的其他响应者对象。

您将事件转发到的响应者应该是您自己的 UIView 子类的实例,并且所有这些对象都必须知道正在发生事件转发,并且在触摸事件的情况下,它们可能会收到未绑定的触摸给他们。

  • 响应事件而重绘自身的自定义视图应该只在事件处理方法中设置绘制状态,并在drawRect:方法中执行所有绘制。

  • 不要显式向响应者发送事件(通过 nextResponder);相反,调用超类实现并让 UIKit 处理响应者链遍历。

Try this link and pay attention to how they solve nested views.

Remember the best Practices for Handling Multitouch Events:

When handling events, both touch events and motion events, there are a few recommended techniques and patterns you should follow.

  • Always implement the event-cancellation methods.

In your implementation, you should restore the state of the view to what it was before the current multitouch sequence, freeing any transient resources set up for handling the event. If you don’t implement the cancellation method your view could be left in an inconsistent state. In some cases, another view might receive the cancellation message.

  • If you handle events in a subclass of UIView, UIViewController, or (in rare cases) UIResponder,

    • You should implement all of the event-handling methods (even if it is a null implementation).

    • Do not call the superclass implementation of the methods.

  • If you handle events in a subclass of any other UIKit responder class,

    • You do not have to implement all of the event-handling methods.

    • But in the methods you do implement, be sure to call the superclass implementation. For example,

[super touchesBegan:theTouches withEvent:theEvent];

  • Do not forward events to other responder objects of the UIKit framework.

The responders that you forward events to should be instances of your own subclasses of UIView, and all of these objects must be aware that event-forwarding is taking place and that, in the case of touch events, they may receive touches that are not bound to them.

  • Custom views that redraw themselves in response to events should only set drawing state in the event-handling methods and perform all of the drawing in the drawRect: method.

  • Do not explicitly send events up the responder (via nextResponder); instead, invoke the superclass implementation and let the UIKit handle responder-chain traversal.

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