Iphone 设置兄弟视图的动画
我有一个UIView的网格,每个视图都附带了一个触摸事件。当一个UIView被触摸时,我想让它的所有兄弟姐妹都消失 有人对此有什么指示吗?褪色的同级可以由被触摸的UIView处理吗,或者视图控制器应该使同级褪色吗 编辑:找到了答案: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]) {
- (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的方式来达到同样的结果
致以最良好的祝愿