2009-07-20 70 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]等方法更改顺序。

相关问题