Domanda

I'm trying to increase the height of a button (via animation) when another button is clicked. The issue I'm having is that instead of increasing it, it decreases it back to the starting height. After doing some searching around on Stackoverflow, it appears that the issue has to do with having autolayout enabled. I tried disabling autolayout and this is exactly the issue. I would like to know though, if there is a work around that doesn't involve disabling autolayout. Here's my code:

self.button.frame = CGRectMake(39, 39, 242, 215);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4f];

self.button.frame = CGRectMake(39, 39, 242, 315);
[UIView commitAnimations];
È stato utile?

Soluzione

You do this by making an IBOutlet to a height constraint you made in IB (called heightCon in my example), and then animating its constant value,

[UIView animateWithDuration:.4 animations:^{
            self.heightCon.constant = 315;
            [self.view layoutIfNeeded];
        }];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top