2011-10-03 41 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的方式來達到同樣的結果。

此致敬禮。