当人们再次看到这个问题弹出时,我可以想象出大量的叹息。但是,我在这里、文档中和通过 Google 都阅读了很多信息,但仍然没有找到解决方案。所以这里什么都没有。
我正在尝试重新创建 Facebook 登录屏幕,其中间距和位置使用键盘进行动画处理,以允许用户仍然看到所有输入字段和登录按钮。
当我使用kCAFillModeForwards
and 设置removedOnCompletion
为NO
. 但是,正如在 SO 上的另一个线程中所说,这似乎只是在视觉上改变了属性,而实际的点击位置没有改变。因此,当用户看似在点击输入字段时,iOS 会将其解释为对背景的点击。
所以我尝试设置新的位置和大小,但是当我这样做时,动画不会播放,它只是捕捉到新的位置。将其放在addAnimation
通话之前和之后,无论有没有交易,都没有任何区别。
仍会调用委托方法,但您无法直观地看到任何动画。
if([notification name] == UIKeyboardWillShowNotification) {
CGRect currBounds = self.loginTable.tableHeaderView.layer.bounds;
CGSize newSize = CGSizeMake(self.loginTable.tableHeaderView.bounds.size.width, 60);
CGPoint newPos = CGPointMake(self.loginTable.layer.position.x, self.loginTable.layer.position.x - 50);
//[CATransaction begin];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
[animation setToValue:[NSValue valueWithCGSize:newSize]];
[animation setDelegate:self];
[self.loginTable.tableHeaderView.layer addAnimation:animation forKey:@"headerShrinkAnimation"];
CABasicAnimation *formPosAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
[formPosAnimation setToValue:[NSValue valueWithCGPoint:newPos]];
[formPosAnimation setDelegate:self];
//formPosAnimation.removedOnCompletion = NO;
//formPosAnimation.fillMode = kCAFillModeForwards;
[self.loginTable.layer addAnimation:formPosAnimation forKey:@"tableMoveUpAnimation"];
//[CATransaction commit];
[self.loginTable.tableHeaderView.layer setBounds:CGRectMake(currBounds.origin.x, currBounds.origin.y, newSize.width, newSize.height)];
[self.loginTable.layer setPosition:newPos];
}