如何处理点击按钮ios?

时间:2014-10-24 07:50:40

标签: ios7

我有3个view.view 0 (0,0,320,300)view 1 (0,300,320,300)view 2 (0,300,320,300)和1个按钮。 view 0没有改变位置。当我没有点击按钮view 2覆盖view 1但是当我点击按钮时,我设置view 2(0,600,320,300)的位置。我在故事板上使用自动布局。

CODE

    - (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];
   }
  }

我不明白,当我点击按钮时,第一个view 2没有改变位置。但是当我点击第二个view 2更改位置时。你可以帮帮我吗? / p>

0 个答案:

没有答案