我有动画代码可以移动按钮和其他一些视图以响应键盘显示:
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)
经过几个小时的调试并找出根本原因后,结果很简单。
解除UIAlertView
触发的自动布局,这是将提交按钮移回原处的位置。设置约束或关闭自动布局并使用自动调整遮罩修复了问题。