下面的代码,我用来显示点击和隐藏的视图,当我再次点击时,它工作正常,但当再次点击时,视图不再隐藏,只是停留在视图中。
- (IBAction)didTapFlag:(id)sender
{
checkBtnCondition=YES;
menuView.hidden=YES;
if([audioPlayer isPlaying])
{
[self playPauseAudio];
}
if( iscommentOn==NO)
{
[mCommentView hide];
iscommentOn=YES;
}
else
{
iscommentOn=NO;
if(iscommentOn)
if(![commentPlayer1 isPlaying])
{
iscommentOn=NO;
}
if(!iscommentOn)
{
iscommentOn=YES;
if(mCommentView)
{
[commentPlayer1 stop];
commentPlayer1 = nil;
[mCommentView hide];
return;
}
float comx;
float comy;
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
comx = 200;
comy = 280;
}
else
{
comx = 50;
comy = 170;
}
mCommentView = [[CommentUtility alloc] initWithFrame:CGRectMake(comx, comy, 330, 250)];
[mCommentView setDelegate:(id)self];
[self.view addSubview:mCommentView];
[mCommentView show];
}
}
}
我的代码应该改变什么,我的代码有任何问题。请帮助我。
答案 0 :(得分:1)
示例代码:
- (IBAction)didTapFlag:(id)sender
{
int btnTag = ((UIButton *)sender).tag;
if (btnTag == 0)
{
[yourView setHidden:YES];
yourButton.tag = 1;
}
else
{
[yourView setHidden:NO];
yourButton.tag = 0;
}
}