Ios7 如何处理点击按钮?
我有3个视图。视图0,0320300,视图1 0300320300,视图2 0300320300和1个按钮。 视图0不会更改位置。当我不单击按钮时,视图2会覆盖视图1,但当我单击按钮时,会设置视图20600320300的位置。我在情节提要上使用自动布局 代码Ios7 如何处理点击按钮?,ios7,Ios7,我有3个视图。视图0,0320300,视图1 0300320300,视图2 0300320300和1个按钮。 视图0不会更改位置。当我不单击按钮时,视图2会覆盖视图1,但当我单击按钮时,会设置视图20600320300的位置。我在情节提要上使用自动布局 代码 我不明白,当我点击按钮时,第一个视图2不会改变位置。但是当我点击第二个视图2时,会改变位置。你能帮我吗?如果你使用自动布局,你不能直接改变框架、边界或中心属性。我可以设置框架..但我添加了约束,它可以改变位置。。。 - (void)
我不明白,当我点击按钮时,第一个视图2不会改变位置。但是当我点击第二个视图2时,会改变位置。你能帮我吗?如果你使用自动布局,你不能直接改变框架、边界或中心属性。我可以设置框架..但我添加了约束,它可以改变位置。。。
- (void)viewDidLoad
{
_contraintAfter = [NSLayoutConstraint constraintWithItem:_view1
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:_view2
attribute:NSLayoutAttributeTop
multiplier:1
constant:0];
_btnInfoView.selected = NO;
}
#pragma mark - Auto Layout
-(void)layoutInfoAppeare
{
[UIView animateWithDuration:0.5
animations:^{
[self.view removeConstraint:_contraintBefore];
[self.view addConstraint:_contraintAfter];
[self.view layoutIfNeeded];
}
completion:^(BOOL finished) {
_view1.hidden = NO;
}];
}
-(void)layoutInfoDisappeare
{
_view1.hidden = YES;
[UIView animateWithDuration:0.5
animations:^{
[self.view removeConstraint:_contraintAfter];
[self.view addConstraint:_contraintBefore];
[self.view layoutIfNeeded];
}];
}
and when i click button i process:
- (IBAction)btnVaccineOtherClick:(id)sender
{
UIButton *btn = (UIButton *)sender;
btn.selected = !btn.selected;
if (btn.selected) {
[self layoutInfoAppeare];
} else {`
[self layoutInfoDisappeare];
}
}