Reputation: 1134
Within the viewDidLoad method, I create a CGPoint with the min X and Y values from the frame of a view. Then I set the anchorPoint of that views layer to 0,0 and its position to the CGPoint. Then I apply a CGAffineTransformScale to make it 0,0 (hide it.) Whenever a user touches a button I want it to animate from its anchorPoint 0,0 (top-left) to full width and height. If the user presses again animate it to 0,0 . However the view is out of place (from the anchor point change) and whenever I scale it on the button press the pop-up animation is not equal to when the layer is animated to hide. That is whenever the layer is made visible you can see it transition from no width and height to full width and height but when it is made invisible it just disappears.
heres viewWillLayoutSubviews
self.original = CGPointMake(CGRectGetMinX(self.menu.frame), CGRectGetMinY(self.menu.frame));
self.menu.layer.anchorPoint = CGPointMake(0, 0);
self.menu.layer.position = self.original;
self.menu.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0, 0);
This is on button click logic
if(self.isMenuVisible)
{
//hide menu
[UIView animateWithDuration:.5 animations:^{
self.menu.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0, 0);
}];
self.isMenuVisible = NO;
}
else
{
//show it
[UIView animateWithDuration:.5 animations:^{
self.menu.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
}];
self.isMenuVisible = YES;
}
Upvotes: 0
Views: 1170
Reputation: 6952
I don't know why zero width and height will cause no animation, but there is a workaround, it is making its width and height scale to 0.01 and when the animation is complete, hide the menu.
if (self.menu.hidden) {
[UIView animateWithDuration:.5 animations:^{
self.menu.hidden = NO ;
self.menu.transform = CGAffineTransformIdentity ;
}] ;
} else {
[UIView animateWithDuration:.5 animations:^{
self.menu.transform = CGAffineTransformScale(self.viewTest.transform, 0.01, 0.01) ;
} completion:^(BOOL finished) {
self.menu.hidden = YES ;
}] ;
}
Upvotes: 2