2013-12-16 33 views
0

我有移动的按钮,并且响应于键盘一些其他示出了动画的代码:UIAlertView中和基于块的动画

NSValue *frameValue = [note userInfo][UIKeyboardFrameEndUserInfoKey]; 
CGRect keyboardFrame = [frameValue CGRectValue]; 
CGFloat keyboardHeight = keyboardFrame.size.height*kCGPKeyboardAnimationTranslationAdjustmentFactor; 
CGFloat animationDuration = [[note userInfo][UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 
UIViewAnimationOptions animationCurveOption = [[note userInfo][UIKeyboardAnimationCurveUserInfoKey] integerValue] >> 16; 

CGPoint submitButtonCenter = [[self submitButton] center]; 
CGPoint offsetSubmitButtonCenter = CGPointMake(submitButtonCenter.x, submitButtonCenter.y-keyboardHeight); 

__block __weak __typeof(self) wSelf = self; 
NSCParameterAssert([wSelf isKindOfClass:[self class]]); 
[UIView animateWithDuration:animationDuration delay:0.0f options:animationCurveOption animations:^{ 

    [[wSelf submitButton] setCenter:offsetSubmitButtonCenter]; 

} completion:nil 
    }]; 

然而该动画被后来撤消,当我显示UIAlertView

- (void)displayError:(NSError*)error { 
    NSCParameterAssert([NSThread isMainThread]); 
    NSString *errorDescription = [error description]; 
    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"" message:errorDescription delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    NSLog(@"%s: Recursive View Description: %@",__PRETTY_FUNCTION__,[[[self view] subviews] description]); 
    [av show]; 
    NSLog(@"Is it still there? %s Recursive View Description: %@",__PRETTY_FUNCTION__,[[[self view] subviews] description]); 
} 

在调用[av show]之后,按钮框架立即发生变化,将其恢复到动画之前的确切位置。注释掉[av show]会使臭虫消失,所以它看起来像是一种副作用。

虽然该代码不存在,但还有其他几个UIView和UITextField对象以相同的方式移位。它们不受影响,只有UIButton在移动。

任何人都有如何解决它的想法?

+0

呃,我认为问题在于你正在使用动画曲线作为选项,它不应该以这种方式使用。可能是其中一个选择导致你的麻烦。 –

+0

@LeoNatan将动画选项参数更改为“UIViewAnimationOptionCurveLinear”不会导致错误消失。 –

回答

0

经过几个小时的调试并找出根本原因后,答案变得非常简单。

关闭UIAlertView触发自动布局,这是将提交按钮移回到之前的位置。设置一个约束或关闭自动布局并使用自动调整掩码来解决问题。