0

我正在显示一个视图,其中有一个按钮。单击此按钮时,我将通过 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]; 
}
4

2 回答 2

0
for (UIView *vw in popup_viewforimage.subviews) {
    if ([vw isKindOfClass:[UIImageView class]]) {
        vw.hidden=YES;
    }
}
于 2013-02-22T12:41:18.793 回答
0

利用

[popup_viewforimage removeFromSuperView];

或者

将它的 alpha 设置为 0

popup_viewforimage.alpha=0.0;
于 2013-02-22T12:36:55.630 回答