2013-08-06 28 views
7

我有一個包含三個容器移動一個UIView上的UITableView的頂部 - 接觸頂部的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的幀(我示出了一個UIView查看(標記爲O)B的右側,這並不重要)。現在容器B是重疊的容器

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

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

但是現在,當我試圖通過觸摸行(@)的左邊緣,選擇在容器C的UITableView的一排,觸摸是由容器的UITableView的註冊。或者即使我觸摸表格(*)上方的視圖,也會選擇A中相應的行。

我可以通過更改容器A的UITableView的寬度來解決部分問題。但是,如果我觸摸表C(@),那麼我仍然有問題,C的行不會選擇。這就像表C的起始位置在舊位置($)中一樣。

那麼,我可以做什麼,以便在新的@位置點擊會在C中選擇正確的行?

=======

編輯一些代碼:

這是我的代碼做容器B.這是B的框架的一個非常簡單的動畫。 self.view是容器B的UIView。

所有視圖都通過故事板顯示在屏幕上(隱藏「其他」容器)。其他容器是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]; 
       } 
]; 

請讓我知道您想查看的其他代碼。

+0

很好的解釋,但我認爲我們需要看到您使用顯示和動畫的容器代碼解決這個問題... – Beppe

+1

@Beppe,我爲動畫添加了代碼。 – David

回答

0

所以,我下載來揭露前從視覺上可以看到(在3D中)視圖發生了什麼。看起來我繪製的圖表並不完整,並且具有誤導性。

每個容器A和B(它們是UIViews)都包含子視圖A'和B'(也是UIViews)。在我改變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和嘗試動畫從žB的位置,檢查B爲A.

+0

感謝您的建議。我將邏輯移至A和B的父ViewController,並且存在相同的行爲。 – David