【发布时间】:2013-12-16 21:29:22
【问题描述】:
我有动画代码可以移动按钮和其他一些视图以响应键盘的出现:
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] 会使 bug 消失,所以它看起来像一个副作用。
虽然该代码不存在,但还有几个其他 UIView 和 UITextField 对象以相同的方式移动。它们不受影响,只有 UIButton 移动。
有人对如何修复它有想法吗?
【问题讨论】:
-
嗯,我认为问题在于您将动画曲线用作选项,不应该以这种方式使用它。可能是导致您的麻烦的选项之一。
-
@LeoNatan 将动画选项参数更改为
UIViewAnimationOptionCurveLinear不会使错误消失。
标签: ios uiview ios7 uikit core-animation