I want to show UIView after button pressed with animation,I can show the view but I am unable to hide it again pressed that button.Here is my code to show/hide the view. To Show the UIView :
sliderView.frame = CGRectMake(130, 20, 0, 0);
[UIView animateWithDuration:0.25 animations:^{
sliderView.frame = CGRectMake(130, 30, 100, 200);
}];
To Hide the UIView :
[UIView animateWithDuration:0.25 animations:^{
sliderView.frame = CGRectMake(130, 30, 0, 0);
}];
Using above code view is showing with animation but not hiding. Does anybody know how to hide it,Please help,Thanks
No, it is not needed in this case. animations and completion are not retained by self so there is no risk of strong retain cycle.
To be exact, whenever you want to animate the view, you actually call layoutIfNeeded on the superview of that view. Try this instead: UIView. animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.
The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:] .
Your code works, i have used it. Look code below
.h file:
#import <UIKit/UIKit.h>
@interface StackoverflowTestViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIView *cautionView;
- (IBAction)btnToggleClick:(id)sender;
@property (strong, nonatomic) IBOutlet UIButton *btnToggle;
@end
.m file:
#import "StackoverflowTestViewController.h"
@interface StackoverflowTestViewController ()
@end
@implementation StackoverflowTestViewController
bool isShown = false;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnToggleClick:(id)sender {
if (!isShown) {
_cautionView.frame = CGRectMake(130, 20, 0, 0);
[UIView animateWithDuration:0.25 animations:^{
_cautionView.frame = CGRectMake(130, 30, 100, 200);
}];
isShown = true;
} else {
[UIView animateWithDuration:0.25 animations:^{
_cautionView.frame = CGRectMake(130, 30, 0, 0);
}];
isShown = false;
}
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With