【问题标题】:UIAlertView and block based animationsUIAlertView 和基于块的动画
【发布时间】: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


【解决方案1】:

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

关闭UIAlertView 触发了自动布局,这就是将提交按钮移回原来位置的原因。设置约束或关闭自动布局并使用自动调整大小的蒙版修复了该问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 2012-03-23
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    相关资源
    最近更新 更多