Reputation: 157
I have the following code to show and hide a uiview however its a very jumpy when hiding the display and the second time i show it. I would like the display to only be hidden when the animation is completed. I have read somwerhe we can do this in xcode however im not sure how i would go about this?
-(IBAction)modal:(id)sender{
if (self.optionsuiview.hidden == YES)
{
[UIView animateWithDuration:0.2 animations:^{
CGRect f = self.optionsuiview.frame;
f.origin.x = 0;
f.origin.y = 42;
self.optionsuiview.frame = f;
}];
self.optionsuiview.hidden = NO;
}
else
{
[UIView animateWithDuration:0.2 animations:^{
CGRect f = self.optionsuiview.frame;
f.origin.x = 0;
f.origin.y = 0;
self.optionsuiview.frame = f;
// self.optionsuiview.hidden = YES;
}];
self.optionsuiview.hidden = YES;
}
}
Upvotes: 0
Views: 345
Reputation: 90117
Use one of the other animation methods, e.g.:
[UIView animateWithDuration:duration animations:^{
// your animation code here
} completion:^(BOOL finished) {
// call after animation is complete
}];
Upvotes: 2
Reputation: 31081
You can use.
[UIView animateWithDuration:0.2
animations:^{
CGRect f = self.optionsuiview.frame;
f.origin.x = 0;
f.origin.y = 0;
self.optionsuiview.frame = f;
}
completion:^(BOOL finished){
self.optionsuiview.hidden = YES;
}];
There is some new way of Animating Views with Block Objects
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations completion:(void (^)(BOOL
finished))completion NS_AVAILABLE_IOS(4_0);
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0
Upvotes: 1