Masonic animationWithDuration does not animate

I am trying to animate a UIWebView at the bottom of my viewController and I am using masonry ( https://github.com/Masonry/Masonry ).

First I create my webview with size 0 - (x, y, height and width) and then I try to animate it so that the webview animates "on top" of the view manager. The webview is shown, but it doesn't animate in place - it appears immediately. Can anyone with experience guide me in the right direction?

This is a button action

-(void)didPressBtn{
    self.infoView = [UIWebView new];
    self.infoView.scalesPageToFit = YES;
    self.infoView.backgroundColor = [UIColor whiteColor];
    self.infoView.delegate = self;
    [self.scrollView addSubview:self.infoView];
    [self.infoView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(0));
    }];


    [self.scrollView layoutIfNeeded];
    //FIXME: Hmmm it doesn't really animate!?
    [UIView animateWithDuration:1 animations:^{
        [self.scrollView setContentOffset:CGPointMake(0, 0)];
        [self.infoView makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.scrollView);
        }];

        [self.scrollView layoutIfNeeded];

    } completion:^(BOOL finished) {
                [self.infoView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:NSLocalizedString(@"INFORMATION_URL", )] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:15]];
    }];
}

      

My viewDidLoad

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.scrollView = [UIScrollView new];
    self.scrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.scrollView];
    [self.scrollView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];

    UIView *contentView = [UIView new];
    [self.scrollView addSubview:contentView];

    [contentView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.width.equalTo(self.scrollView);
    }];

//Then adding buttons and such...
}

      

+3


source to share


1 answer


One quick observation for didPressButton

. You use mas_makeConstraints

to set the edges to be equal @0

, and immediately afterwards use mas_makeConstraints

to change them again so that the scroll is filled. This adds conflicting constraints at the top of the first set.

Instead, you can use mas_remakeConstraints

this view to replace existing constraints.

In terms of animation, I use a template to update the constraints first (not inside the animation block) and then animate the layout:



[UIView animateWithDuration:1
        animations:^{
            [theParentView layoutIfNeeded];
        }];

      

See also How do I change animation constraint changes?

+15


source







All Articles