我有一个视图,我想在键盘显示时改变它的位置,我使用 UIKeyboardWillShowNotification 委托更新位置,它在IOS 7设备中完美运行但是当我尝试运行它时在IOS 8设备中,然后视图未重新定位,框架会更新,因为我可以在日志中看到它。
以下是我的代码
-(void) keyboardWillShow:(NSNotification*) notification{
@autoreleasepool {
CGRect frame = _loginFrame.frame;
frame.origin.y-=200;
DLog(@"login frame %@ ",NSStringFromCGRect(frame));
[UIView animateWithDuration:0.25 animations:^{
[_loginFrame setFrame:frame];
}];
}
}
但是,当我在dispatch_after中尝试阻止动画到新位置
时 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.25 animations:^{
[_loginFrame setFrame:frame];
}];
});
任何想法为什么没有dispatch_after?框架没有动画到新位置?
谢谢!
注意:看起来像setFrame:方法不起作用,不知道为什么,我已经创建了一个基本的ios 8应用程序来测试这个
2014-09-11 18:59:54.836 KeyboardCheck [31215:1451974]键盘显示 2014-09-11 18:59:54.837 KeyboardCheck [31215:1451974] 旧框架 {{60,269},{200,30}} 2014-09-11 18:59:54.837 KeyboardCheck [31215:1451974] 更新框架{{60,169},{200,30}} 2014-09-11 18:59:55.339 KeyboardCheck [31215:1451974] 完成 阻止框架{{60,269},{200,30}} 2014-09-11 18:59:55.822 KeyboardCheck [31215:1451974]键盘隐藏2014-09-11 18:59:55.822 KeyboardCheck [31215:1451974] 旧框架{{60,269},{200,30}} 2014-09-11 18:59:56.324 KeyboardCheck [31215:1451974] 完成 阻止框架{{60,269},{200,30}}
答案 0 :(得分:3)
我通过取消选中使用自动布局解决了我的问题。
如果您想要自动布局,这是另一种可能的解决方案:
https://teamtreehouse.com/forum/animating-views-does-not-seem-to-work-in-ios8-but-did-in-ios7