我有一个UIButton
。现在我在Subview
添加按钮: -
UIButton* button4 = [[UIButton alloc] initWithFrame:frame4];
[button4 setBackgroundImage:image3 forState:UIControlStateNormal];
[button4 setShowsTouchWhenHighlighted:YES];
[button4 addTarget:self action:@selector(Nofication:) forControlEvents:UIControlEventTouchDown];
- (void)Nofication:(id)sender
{
share=[[UIView alloc]init];
share.frame=CGRectMake(300, 60, 130, 100);
[self.view addSubview:share];
[UIView animateWithDuration:2.0
animations:^{
share.frame =CGRectMake(180, 50, 130, 100); // its final location
}];
share.backgroundColor=[UIColor yellowColor];
login=[[UIButton alloc]init];
login.frame=CGRectMake(0, 0, 130, 50);
[login setBackgroundImage:[UIImage imageNamed:@"login.png"] forState:UIControlStateNormal];
[login addTarget:self action:@selector(asubmit:) forControlEvents:UIControlEventTouchDown];
[share addSubview:login];
login.layer.borderColor = [[UIColor whiteColor]CGColor];
policies=[[UIButton alloc]init];
policies.frame=CGRectMake(0, 50, 130, 50);
[policies setBackgroundImage:[UIImage imageNamed:@"Policies.png"] forState:UIControlStateNormal];
[policies addTarget:self action:@selector(apolicies:) forControlEvents:UIControlEventTouchDown];
[share addSubview:policies];
}
当我点击按钮时,它的开放子视图工作得很好。但是现在我需要如果子视图在那个时间单击按钮显示它需要隐藏子视图。如果我点击按钮时未显示subview
,则需要显示subview
。所以请给我任何想法。
如何显示和隐藏相同的UIButton
先谢谢。
答案 0 :(得分:1)
UIView上有一个hidden
属性。 https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/occ/instp/UIView/hidden
if (button.isHidden) {
button.hidden = NO;
}
答案 1 :(得分:0)
[subview setHidden:![subview isHidden]];
编辑:
在Notification
函数中:
// Be sure that the view is loaded, maybe load it at a different place or use a boolean
if([subview isHidden]){
[subview setHidden:false];
}else{
[subview setHidden:true];
}
答案 2 :(得分:0)
您可以在button4.selected = !button4.selected
方法中设置Nofication:
。
然后,您可以检查button4.isSelected
并使用hidden
属性隐藏/显示子视图
希望它有所帮助。