2011-10-03 38 views
0

我有一个UIViews网格,每个都有一个触摸事件附加。当一个UIView被触动时,我想淡化所有的兄弟姐妹。动画同胞视图

有没有人有任何方向给这个?可以通过被触摸的UIView处理衰落的兄弟姐妹,或者视图控制器是否应该淡化兄弟姐妹?

编辑:想通了:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    for (UIView *subview in [self.superview subviews]) { 
     if (subview != self) { 
      subview.layer.opacity = 0.5; 
     }  
    } 

    [super bringSubviewToFront:self]; 

} 

回答

1

您还可以在UIView的水平做到这一点。只需将您的更改包装到UIView动画块中的视图的alpha中即可。像这样:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    for (UIView *subview in [self.superview subviews]) { 
    if (subview != self) { 
     [subview setAlpha:0.5]; 
    }  
    } 
    [UIView commitAnimations];  
    [super bringSubviewToFront:self]; 

} 

这应该会在半秒内将所有子视图淡出半透明度。你已经分类了,但我只是想我会用UIView的方式来达到同样的结果。

此致敬礼。