如何通过动画隐藏视图内容

时间:2013-02-22 12:32:29

标签: iphone

我正在显示一个视图,其中有一个按钮。单击此按钮,我将通过在Objective C中定义的动画方法显示PopUp视图,并在Popup视图上添加图像。然后在视图上点击此按钮弹出视图通过设置其宽度和高度等于零来隐藏,但是它上面的图像没有隐藏。我可以隐藏它吗? 这些是我正在使用的方法..

点击按钮后调用此方法..

-(void)btnImageClkForPopUp:(id)sender
{  
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.5];
popup_viewforimage.frame=CGRectMake(8, 30, 300, 250);
popup_viewforimage.backgroundColor=[UIColor whiteColor];

UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 250)];
imgview.image=[UIImage imageNamed:@"apple.jpeg"];
[popup_viewforimage addSubview:imgview];

[self.view addSubview:popup_viewforimage];   
[UIView commitAnimations];
}

在视图上点击触摸后,调用这两种方法来隐藏它

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isKindOfClass:[UIButton class]])
{ 
 return NO;
}
return YES;   
}

-(void)hidekeyboard
{
 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:2.5];
 popup_viewforimage.frame=  CGRectMake(15, 65, 0, 0);
 popup_viewforimage.backgroundColor=[UIColor grayColor];
 [self.view addSubview:popup_viewforimage];
  [UIView commitAnimations]; 
}

2 个答案:

答案 0 :(得分:0)

使用

[popup_viewforimage removeFromSuperView];

OR

将其alpha设置为0

popup_viewforimage.alpha=0.0;

答案 1 :(得分:0)

for (UIView *vw in popup_viewforimage.subviews) {
    if ([vw isKindOfClass:[UIImageView class]]) {
        vw.hidden=YES;
    }
}