Giter Club home page Giter Club logo

Comments (4)

cloudkite avatar cloudkite commented on July 22, 2024 3

@trustyfrog there are two approaches to animating constraints with Masonry. Theres a couple of examples of both approaches in the example project

1. Using reference to the constraint

[self.summaryView makeConstraints:^(MASConstraintMaker *make) { 
    self.animatableConstraint = make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(80, 10, 10, 10));
}];
// update constants values
self.animatableConstraint.insets(UIEdgeInsetsMake(90, 20, 20, 20));

// ensure layout happens in animation block
[self.summaryView setNeedsLayout];

[UIView animateWithDuration:2.5 animations:^{
    [self.summaryView layoutIfNeeded];
}];

2. An alternative approach is to use updateConstraints

//add property to store insets
@property (nonatomic, assign) UIEdgeInsets summaryInsets;

//create all constraints in update constraints
- (void)updateConstraints {
    [super updateConstraints];
    [self.summaryView updateConstraints:^(MASConstraintMaker *make) { 
        make.edges.equalTo(self.view).with.insets(self.summaryInsets);
    }];
}
// update constants values
self.summaryInsets = UIEdgeInsetsMake(90, 20, 20, 20);

// tell constraints they need updating
[self setNeedsUpdateConstraints];

// update constraints now so we can animate the change
[self updateConstraintsIfNeeded];

[UIView animateWithDuration:2.5 animations:^{
    [self layoutIfNeeded];
}];

Let me know if that helps. If you are changing the layout more drastically ie aligning self.summaryView to different views you will need to uninstall old constraints and install new ones to keep Auto Layout happy. However by the sounds of it you just want to update the insets so the above examples should work for you.

from masonry.

notapplicableio avatar notapplicableio commented on July 22, 2024

Thanks for that Jonas.

In the end I added an additional view to "host" the location of the window and added a reference to the constraint. This let me animate using the centre constraint which feels a neater solution albeit with the overhead of an additional view.

from masonry.

aalenliang avatar aalenliang commented on July 22, 2024

Wonder what about Cocoa?

from masonry.

nitishmakhija avatar nitishmakhija commented on July 22, 2024

@cloudkite [super updateConstraints]; should be called at the end of the - (void)updateConstraints; as per apple's documentation

from masonry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.