iOS: Animating a View (Sample of hiding a UITabBarController view)
The UIView class has it's animation methods like beginAnimations, commitAnimations,
animateWithDuration, and setAnimationDuration.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
// CGRect temp = appDelegate.tabBarController.view.frame;
// temp.origin.y += 100;
for(UIView *view in appDelegate.tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(-320, view.frame.origin.y, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
[UIView animateWithDuration:.7
animations:^(void) {
for(UIView *view in appDelegate.tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(-320, view.frame.origin.y, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
completion:^(BOOL finished) {
appDelegate.tabBarController.tabBar.hidden = YES;
}];
animateWithDuration, and setAnimationDuration.
You can use this methods to animate such specific view.
Below is an example of hiding a UITabBarController view and retain the non-UITabBar class views.
Below is an example of hiding a UITabBarController view and retain the non-UITabBar class views.
[UIView setAnimationDuration:0.5];
// CGRect temp = appDelegate.tabBarController.view.frame;
// temp.origin.y += 100;
for(UIView *view in appDelegate.tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(-320, view.frame.origin.y, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
or you can also do like this,
[UIView animateWithDuration:.7
animations:^(void) {
for(UIView *view in appDelegate.tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(-320, view.frame.origin.y, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
completion:^(BOOL finished) {
appDelegate.tabBarController.tabBar.hidden = YES;
}];
Hope this helps!
Comments
Post a Comment