I want a button to trigger the following action. When clicked it’s supposed to push my logo up and out of the view and remove it. When it’s clicked once more it’s supposed to do the reverse thing. Meaning the image is created and pushed down back into the view. I’m using storyboard to set up my interface. My issue is that I can’t get the animation to trigger. Posting my code below:
In TableViewController.h
@interface TableViewController : UITableViewController{
BOOL status;
}
@property (weak, nonatomic) IBOutlet UIImageView *animateLogo;
@property (weak, nonatomic) IBOutlet UIButton *button;
- (IBAction)onClick:(id)sender;
- (void)showHideView;
@end
In TableViewController.m
@synthesize animateLogo, button;
- (void)viewDidLoad{
[super viewDidLoad];
status = YES;
}
- (IBAction)onClick:(id)sender{
[self showHideView];
}
if(status){
[UIView
animateWithDuration:1.5
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
[animateLogo setFrame:CGRectOffset([animateLogo frame], 0, -animateLogo.frame.size.height)];
}
completion:^(BOOL completed) {}
];
status = NO;
[button setTitle:@"Show" forState:UIControlStateNormal];
}
else{
[UIView
animateWithDuration:1.5
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
[animateLogo setFrame:CGRectOffset([animateLogo frame], 0, animateLogo.frame.size.height)];
}
completion:^(BOOL completed) {}
];
status = YES;
[button setTitle:@"Hide" forState:UIControlStateNormal];
}
}
EDIT:
The animation is working if I programmatically code the UIImageView. So the issue is with the storyboard somehow. I prefer to get this working with storyboard so I can get a better overlook on the layout.
UIImage *test = [UIImage imageNamed:@"logo.png"];
animateLogo = [[UIImageView alloc] initWithImage:test];
[self.view addSubview:animateLogo];
[animateLogo setFrame:CGRectOffset([animateLogo frame], 0, animateLogo.frame.size.height)];
Problem sovled. I used a different approach were I animated the UIView instead of the UIImageView. I’s now working like a charm.