I'm trying to do a simple animate of a UIView
and the problem is that the view doesn't expand/collapse as I want it to do, it only snaps to the end of the animation without moving there. Here is my code:
- (IBAction)policeReportedChanged:(id)sender {
if (self.policeReportedSwitch.isOn) {
[self.policeReportNumberColl setHidden:NO];
[UIView animateWithDuration:1.0f
animations:^
{
[self.policeReportNumberColl setFrame:CGRectMake(0, 130, 320, 65)];
[self.damageView setFrame:CGRectMake(0, 200, 320, 200)];
}
completion:^(BOOL finished)
{
}
];
} else {
[UIView animateWithDuration:1.0f
animations:^
{
[self.policeReportNumberColl setFrame:CGRectMake(0, 0, 0, 0)];
[self.damageView setFrame:CGRectMake(0, 135, 320, 200)];
}
completion:^(BOOL finished)
{
[self.policeReportNumberColl setHidden:YES];
}
];
}
I have set the animation to reveal the UIView policeReportNumberColl
when the switch is turned on and collapsed when it isn't. damageView
is a UIView below that should move up or down to take the space where the revealed view are or not. Inside policeReportNumberColl
are one UILabel
and one UITextfield
.
I have checked around a lot but can't find anything other than this should work.
EDIT:
I have played around a bit and figured out that it has something to to with which object is sending the action. It DOES work it I connect the animation to a Touch up inside
on a UIButton
but it does NOT work if I use on Value Changed
on my UISwitch
like I want to. See code below:
//Does work
- (IBAction) buttonClicked
{
[UIView animateWithDuration:1.0f
animations:^
{
[self.damageView setFrame:CGRectMake(0, 0, 0, 0)];
}
completion:^(BOOL finished)
{
NSLog(@"Klar");
}
];
}
//Does NOT Work
- (IBAction)switchValueChanged {
[UIView animateWithDuration:1.0f
animations:^
{
[self.damageView setFrame:CGRectMake(0, 0, 0, 0)];
}
completion:^(BOOL finished)
{
NSLog(@"Klar");
}
];
}
Does anyone have any idea how to do this on a UISwitch onValueChanged
?