Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 设置兄弟视图的动画_Iphone_Objective C_Ios_Ipad - Fatal编程技术网

Iphone 设置兄弟视图的动画

Iphone 设置兄弟视图的动画,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,我有一个UIView的网格,每个视图都附带了一个触摸事件。当一个UIView被触摸时,我想让它的所有兄弟姐妹都消失 有人对此有什么指示吗?褪色的同级可以由被触摸的UIView处理吗,或者视图控制器应该使同级褪色吗 编辑:找到了答案: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UIView *subview in [self.superview subviews]) {

我有一个UIView的网格,每个视图都附带了一个触摸事件。当一个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];

}

也可以在UIView级别执行此操作。只需将对视图alpha的更改包装到UIView动画块中即可。像这样:

- (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的方式来达到同样的结果

致以最良好的祝愿