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在移动。
任何人都有如何解决它的想法?
呃,我认为问题在于你正在使用动画曲线作为选项,它不应该以这种方式使用。可能是其中一个选择导致你的麻烦。 –
@LeoNatan将动画选项参数更改为“UIViewAnimationOptionCurveLinear”不会导致错误消失。 –