Animate intrinsicContentSize changes

后端 未结 6 820
借酒劲吻你
借酒劲吻你 2021-01-30 08:15

I have a UIView subclass that draws a circle whose radius changes (with nice bouncy animations). The view is deciding the size of the circle.

I want this UIView subclass

6条回答
  •  故里飘歌
    2021-01-30 09:00

    Width / height constraint doesn't help? Keep reference of this constraint and ...

    [NSLayoutConstraint constraintWithItem:view
                                 attribute:NSLayoutAttributeWidth
                                 relatedBy:NSLayoutRelationEqual
                                    toItem:nil
                                 attribute:NSLayoutAttributeNotAnAttribute
                                multiplier:1
                                  constant:myViewInitialWidth];
    

    ... when you do want to animate myView resize, do this ...

    self.viewWidthConstraint.constant = 100; // new width
    [UIView animateWithDuration:0.3 animations:^{ [view layoutIfNeeded]; }];
    

    ... do the same thing for the height.

    Depends on your other constraints, maybe you will be forced to raise priority of these two constraints.

    Or you can subclass UIView, add - (void)invalidateIntrinsicContentSize:(BOOL)animated and fake it by yourself. Get new size from - (CGSize)intrinsicContentSize and animate it by animating width / height constraints. Or add property to enable / disable animations and override invalidateIntrinsicContentSize and do it inside this method. Many ways ...

提交回复
热议问题