2012-06-14 42 views
1

我有sendSubviewToBackinsertSubview:belowSubview:方法有問題不工作。簡單地說,我有一個按鈕,我在另一個視圖_centerView下面插入。我想讓按鈕保持在_centerView以下。問題與sendSubviewToBack和insertSubview:belowSubview:他們應該

我面臨的問題是,當我在_centerView下方插入一個按鈕時,我看到_centerView上閃爍(只是很短的時間)。我試過sendSubviewToBack:insertSubview:belowSubview: - 效果相同。

你有什麼想法可能是錯誤的東西?我錯過了什麼嗎?這裏是我的代碼:

UIButton* itemButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [itemButton setFrame:CGRectMake(0, 0, 40, 40)]; 
    [itemButton setCenter:_centerView.center]; 

    [parentView bringSubviewToFront:_centerView]; 
    [parentView insertSubview:itemButton belowSubview:_centerView]; 
+0

..以及當你刪除'bringSubviewToFront:'? – skram

+0

@skram什麼都沒有,沒有區別。 – RaffAl

回答

0

好了,經過一段時間它原來,這是窗口的錯,我的動畫,同時我添加的按鈕。我不知道爲什麼,但窗口動畫的淡入造成了這個問題。我切換了我的UIWindow的動畫,現在它可以工作。感謝幫助!

0

我不知道背後insertSubview內部結構是什麼,但如果你想擺脫閃爍的,最簡單的方法是將其插入和展前隱藏視圖之後再次。

[itemButton setHidden:YES]; 
[parentView insertSubview:itemButton belowSubview:_centerView]; 
[itemButton setHidden:NO]; 

不是最優雅的解決方案,但它應該完成工作。

+0

我試過了,但是ti沒有做任何改變。還是一樣。 – RaffAl

+0

嗯。如果你拿出'[itemButton setHidden:NO]',那麼它還會閃爍嗎?如果不是,您可能需要隱藏它,直到它從_centerView後面出現。儘管如此,我無法在我的設備上重現此問題,因此我不確定這是否會有所幫助。 –

2

我最近遇到了同樣的問題,但通過此選項可將動畫代碼固定它。希望這對你也有幫助。雖然沒有你的評論,我不會拿出我的解決方案,所以謝謝:)

UIViewAnimationOptionShowHideTransitionViews 
相關問題