2009-07-20 72 views
0

我有一個問題,我已經設計與UIButtons一個應用程序和它的下面是一個的UIImageView。我的問題是,當我啓動我的應用UIButtons在UIImageView下。這是我的UIButtons代碼。的UIImageView重疊的UIButton

代碼:

CALayer *touchedLayer = [myUIButton layer]; 
CABasicAnimation *wiggleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"]; 

wiggleAnimation.duration = .1; 
wiggleAnimation.repeatCount = 1e100f; 
wiggleAnimation.autoreverses = YES; 

wiggleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DRotate(touchedLayer.transform, -.15 , 0.0 , -1.0 ,-1.5)]; 
wiggleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(touchedLayer.transform, -.15 , 0.0 , -1.0 ,-1.5)]; 

[touchedLayer addAnimation:wiggleAnimation forKey:@"wiggle"]; 

當動畫開始我UIButtons得到的下面,和我的UIImageView那張UIButtons以上,爲什麼?


這裏發生了什麼,我在IB設計它首先我把UIImageView,然後四個UIButtons。 UIImageView只是作爲我的四個UIButton的背景。 當應用程序開始正確顯示所有內容時,但當單擊圖標執行代碼時,問題就會開始。

這是我所觀察到的,四個UIButtons,看起來像閃爍,仍然可以接受點擊的事件。我的結論是,UIButtons仍然在UIImageView之上,但是顯示它們時出現問題。

可能是有什麼看法的原因,你可以建議的東西,我還可以做我的目標。

謝謝

回答

1

在動畫過程中,視圖將保持相同的Z順序。我假設(因爲你沒有包括那部分代碼),你已經添加了UIButtonView和UIImageView,這樣它們就不會重疊,當然物體重疊時z順序只會變得明顯。 z順序由您將子視圖添加到其父視圖的順序決定。

爲了使UIButtonView出現在UIImageView之上,最後添加它們。您還可以使用[sendSubviewToBack]和[bringSubviewToFront]等方法更改順序。

相關問題