2013-03-07 39 views
0

我試圖實現我自己的CustomUIActionSheet。UIActionSheet showInView方法如何插入其視圖?

我有它幾乎工作,但我不知道showInView方法如何工作。

  • (無效)showInView:(UIView的*)查看

給人一種觀點,這種方法可以把它認爲在每一個單一視圖的前面(將其添加到Windows也許?),但它也能夠根據添加的視圖來設置旋轉。

我試着將它添加到我接收的視圖的窗口作爲參數。

CGFloat startPosition = view.window.bounds.origin.y + view.window.bounds.size.height; 

self.frame = CGRectMake(0, startPosition, view.window.bounds.size.width, [self calculateSheetHeight]); 

[view.window addSubview:self]; 

self.blackOutView = [self buildBlackOutViewWithFrame:view.window.bounds]; 
[view.window insertSubview:self.blackOutView belowSubview:self]; 

通過,當我在景觀呈現的動作片這樣做,所有的作品,只是,動作片從右側apears(因爲Windows系統引用其始終不變)

從來就還試圖將其添加到視圖窗口那樣的RootViewController的:

UIView * view = view.window.rootViewController.view; 

CGFloat startPosition = view.bounds.origin.y + view.bounds.size.height; 

self.frame = CGRectMake(0, startPosition, view.bounds.size.width, [self calculateSheetHeight]); 

[view addSubview:self]; 

self.blackOutView = [self buildBlackOutViewWithFrame:view.bounds]; 
[view insertSubview:self.blackOutView belowSubview:self]; 

但同樣,它在景觀失敗,它不添加任何東西,或者至少,我看不出它

所以,我的問題是,我該如何將視圖添加到以兩種方向工作的層次結構的頂部?

非常感謝!

回答

1

在閱讀了一些定製警報視圖的源代碼和其他在層次結構頂部排列的ui組件後,我發現了一個工作解決方案。

添加視圖窗口的第一子視圖:

UIView * topView = [[view.window subviews] objectAtIndex:0]; 

所以最終的代碼是

UIView * topView = [[view.window subviews] objectAtIndex:0]; 

CGFloat startPosition = topView.bounds.origin.y + topView.bounds.size.height; 

self.frame = CGRectMake(0, startPosition, topView.bounds.size.width, [self calculateSheetHeight]); 

[topView addSubview:self]; 

self.blackOutView = [self buildBlackOutViewWithFrame:topView.bounds]; 
[topView insertSubview:self.blackOutView belowSubview:self];