我有以下代码来显示和隐藏一个uiview,但是当它隐藏显示器时它非常跳跃,第二次显示它。我想只在动画完成时隐藏显示。我已经读过somwerhe我们可以在xcode中做到这一点但是我不知道我会怎么做呢?
-(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;
}
}
答案 0 :(得分:2)
使用其中一个animation methods,例如:
[UIView animateWithDuration:duration animations:^{
// your animation code here
} completion:^(BOOL finished) {
// call after animation is complete
}];
答案 1 :(得分:1)
你可以使用。
[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;
}];
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