将UIView移动到UITableView的顶部 - 触摸顶部UIView仍然会选择表格行

7

我有一个包含三个容器的UIView

Container A - contains a UITableView
Container B - contains Container C and Container O
Container C - contains a UITableView
* - touch event
@ - touch event

----------------------
|     |               |
| ---*|      B        |
| --- |               |
| -A- | -----------   |
| --- ||@----C---- |  |
|     | -----------   |
----------------------

一个事件发生了,我改变了容器B的框架(并显示了一个标记为O的视图在B的右侧,这不重要)。现在容器B与容器A重叠。

O - Other view (unimportant)
$ - original location of touch @

----------------------
|   |               | | 
| --|*     B        | |
| --|               | |
| -A|------------   |O|
| --||@-$--C----|   | |
|   |------------   | |
----------------------

但是现在,当我尝试通过触摸行的左边缘(@)选择容器C的UITableView中的一行时,触摸被Container A的UITableView注册。或者即使我在表格上面的视图上触摸(*),也会选择A中相应的行。

我可以通过更改Container A的UITableView的宽度来解决部分问题。但是,如果我触摸表C(@),则不会选择C的行。就像它认为表C的开头在旧位置($)一样。

那么我该怎么做才能在新的@位置点击时选择正确的C中的行呢?

=======

编辑带有一些代码:

这是我在Container B中执行的代码。它是B框架的非常简单的动画。self.view是Container B的UIView。

所有视图都通过Storyboard显示在屏幕上(“其他”容器被隐藏)。其他容器是B的子视图。

// this code basically aligns the "other" container to the right/"offscreen" of 
// Container B. Yes extending beyond the frame of B, but this part works fine
CGRect otherContainerFrame = self.otherContainerView.frame;
otherContainerFrame.origin.x = CGRectGetMaxX(self.view.frame);
[self.otherContainerView setFrame:otherContainerFrame];
[self.otherContainerView setHidden:NO];

// I'm going move Container B by the width of the "other" view
float offset = CGRectGetWidth(self.otherContainerView.frame);

CGRect frame = self.view.frame;
frame.origin.x -= offset;
[UIView animateWithDuration:.35
                 animations:^{
                     [self.view setFrame:frame];
                 }
];

请告诉我您想看到的其他代码。

非常好的解释,但我认为我们需要看到您用来显示和动画化容器的代码才能解决这个问题... - Giuseppe Garassino
1
@Beppe,我添加了用于动画的代码。 - user1494556
2个回答

0

所以我下载了Reveal来直观地看到(在3D中)视图发生了什么。看起来我画的图不完整,且误导。

容器A和B(它们是UIView)中各包含子视图A'和B'(也是UIView)。在动画块中,当我改变self.view时,我实际上是在移动B'的框架。该框架移出了B的边界。

----------------------
|  A' |      B'       |
| ---*|      B        |
| --- |               |
| -A- | -----------   |
| --- ||@----C---- |  |
|     | -----------   |
----------------------

所以即使B'重叠在A和A'上,我想在视图层次结构中,触摸仍然被底层子视图(容器)A和B捕获。我不完全认为这是应该发生的方式,但我猜这就是事情的发展。

无论如何,解决方案很简单。

改为:

[self.view setFrame:frame];

我基本上要做的是:

[self.view.superview setFrame:frame];

0

嗯...不确定这是否适用于您的情况,但请尝试在一个大容器中管理您的动画,该容器包含所有其他容器。

我的意思是,创建一个包含A、B、O及其子视图的容器Z,并尝试从Z中对B的位置进行动画处理,确保B在A的前面。


谢谢建议。我将逻辑移到A和B的父视图控制器中,但是相同的行为仍然存在。 - user1494556

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接