Limitations do not work when resizing a UIView through animation

Oddly enough, I am looking now, I know that adding restrictions to AutoLayout IB is simple. But I really could not understand why my simple limitations do not work when I resize (ZoomIn Animation) UIView.

The view I aimed at zoomIn works fine, but there is no proper presentation in it. It seems that the restrictions do not work.

From this setting, where in the yellow boxes are UIViews and the green boxes are UIImageViews. When I tapped the yellow box, it should zoom in, as shown in the photo below.

enter image description here

These are the limitations:
enter image description here

This should be the expected result when animating ZoomIn. But I’m out of luck, the yellow box is zoomIn, but the green box is turned back and has not been resized.

, , topSpace bottomSpace Yellow Box Green Box . :

- (void) resizeViewWithZoomInAnimation: (UIView*)view duration:(float)secs option:(UIViewAnimationOptions) option {

//sets the new width and height of deal view
float newWidth = view.superview.frame.size.width - 20;
float newHeight = view.superview.frame.size.height - 20;

[UIView animateWithDuration:secs delay:0.0 options:option
                 animations: ^{

                     switch ([view tag]) {
                         case 1:
                             [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, newWidth, newHeight)];
                             break;
                         case 2:
                             [view setFrame:CGRectMake(CGRectGetMaxX(view.frame),CGRectGetMinY(view.frame), -newWidth , newHeight)];
                             break;
                         case 3:
                             [view setFrame:CGRectMake(CGRectGetMinX(view.frame),CGRectGetMaxY(view.frame), newWidth , -newHeight)];
                             break;
                         case 4:
                             [view setFrame:CGRectMake(CGRectGetMaxX(view.frame),CGRectGetMaxY(view.frame), -newWidth, -newHeight)];
                             break;
                     }
                 }
                 completion:nil];
}

zoomIn Animation: image

+4
3

. .

IBOutlets .

[containerView layoutIfNeeded]; // complete pending layout operations (optional)
[UIView animateWithDuration:1.0 animations:^{

    // Update constraints
    self.viewConstraint1.constant = NEW_VALUE;
    self.viewConstraint2.constant = NEW_VALUE;

    // Animate the changes
    [containerView layoutIfNeeded]; 
}];

, layoutIfNeeded - ( ) , .

Auto Layout Apple .

+15

, . , :

yourView.translatesAutoresizingMaskIntoConstraints = YES;
+2

, UIViewController

  [self.view layoutIfNeeded];
  [UIView animateWithDuration:.5
                         animations:^{
                             myConstraint.constant = 64;
                             [self.view layoutIfNeeded];
                         }
                         completion:^(BOOL finished) {
                             // whatever
                         }];

. Apple layoutIfNeeded , . , .

, layoutIfNeeded , , , . @nkukushkin .

It is also important to properly configure your restrictions. The "fix constraints" tool in IB will not necessarily configure them so that it works correctly for animation. For me, I had to go through them and think about how I want the dependencies to work, which, of course, was expected, but it may not be obvious to the newbie (and leads to errors).

+1
source

Source: https://habr.com/ru/post/1527651/


All Articles