我无法可靠地获得键盘的实际高度.我正在添加一个自定义工具栏,它意味着直接放在键盘上方.为了实现布局约束,我在屏幕底部和工具栏底部之间添加了一个静态空间约束.当键盘显示时,我将此约束修改为键盘的高度,这在iOS 8中有很大差异.
为了调整spacer的大小,我目前使用以下方法被触发 UIKeyboardDidShowNotification
-(void)keyboardDidShow:(NSNotification*)notification
{
CGFloat height = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].height;
self.shimConstraint.constant = height;
[self.view layoutIfNeeded];
}
Run Code Online (Sandbox Code Playgroud)
这有时会正确调整约束,但通常返回的键盘高度完全不正确.一旦显示键盘,可靠地获得键盘高度的最佳方法是什么?
编辑:应用程序允许用户在许多不同的输入字段之间切换.其中一些禁用了自动更正,因此自动更正栏可能会隐藏,也可能不会隐藏,切换字段时会返回不正确的高度.
我刚刚将我的iPhone 4从iOS 4.2.1升级到4.3.2,再升级到XCode 4.0.2,我遇到了uiview动画的一些奇怪问题.当我第一次启动我的应用程序时,这样的代码执行完美:
[UIView beginAnimations:@"fadeAlphaIn" context:nil];
[UIView setAnimationDuration:0.5f];
viewClue.alpha = 1.0f;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
但是,在解雇了一个演示文稿然后通过标准方法解雇一个模态视图之后:
[self presentModalViewController:more animated:YES];
Run Code Online (Sandbox Code Playgroud)
和
[self dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
第一个动画不再有效.例如,viewClue视图只是从alpha = 0跳转到alpha = 1,而不是淡入.同样,其他动画改变其他视图的frame属性只会强制帧从初始值跳转到最终值而不动画.在提出和驳回模态视图之前,这些动画工作正常.
我知道其他人在升级到iOS 4.3.2时遇到了动画问题,但模态视图扰乱动画的方式似乎很奇怪.还有其他人遇到过这个问题吗?关于解决方案的任何想法?我正在考虑将模态视图添加为子视图并将其隐藏并显示为动画,但使用标准模态视图方法将更受欢迎.
谢谢你的帮助,
詹姆士
编辑:一些代码显示应用程序的地图是如何动画的
-(void) viewMapfunc
{
AudioServicesPlaySystemSound(soundID);
if(mapvisible){
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
map.frame = CGRectMake(0, 350, 320, 27);
mapscroll.frame = CGRectMake(0, 27, 320, 0);
}
completion:nil];
mapvisible = NO;
viewMapLabel.text = @"View Map";
}else {
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
map.frame = CGRectMake(0, 50, 320, 300);
mapscroll.frame = CGRectMake(0, 27, 320, …Run Code Online (Sandbox Code Playgroud)