大佬教程收集整理的这篇文章主要介绍了objective-c – iOS中不推荐使用的常量,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
if ([[[UIDevice currentDevice] systemVersion] compare:@"3.2" options:NSNumericSearch] != NSorderedAscending) [[aNotification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds]; else [[aNotification.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &keyboardBounds];
这实际上工作正常,但Xcode警告我UIKeyboardBoundsUserInfoKey已被弃用.如何在不压制任何其他警告的情况下摆脱此警告?
另外,有没有办法简单地检查是否定义了UIKeyboardBoundsUserInfoKey以避免检查iOS版本?我试过检查它是否为NULL或nil甚至弱连接UIKit但似乎没有任何工作.
提前致谢
至于运行时检查,我认为你更好testing for the new constant:
&UIKeyboardFrameEndUserInfoKey!=nil
所以,这就是我实际上要做的键盘框架(基于这个other answer):
-(void)didShowKeyboard:(Nsnotification *)notification { CGRect keyboardFrame = CGRectZero; if (&UIKeyboardFrameEndUserInfoKey!=nil) { // Constant exists,we're >=3.2 [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame]; if (UIInterfaceOrientationIsPorTrait([[UIDevice currentDevice] orientation])) { _keyboardHeight = keyboardFrame.size.height; } else { _keyboardHeight = keyboardFrame.size.width; } } else { // Constant has no value. We're <3.2 [[notification.userInfo valueForKey:@"UIKeyboardBoundsUserInfoKey"] getValue: &keyboardFrame]; _keyboardHeight = keyboardFrame.size.height; } }
我实际上在3.0设备和4.0模拟器上测试了这个.
以上是大佬教程为你收集整理的objective-c – iOS中不推荐使用的常量全部内容,希望文章能够帮你解决objective-c – iOS中不推荐使用的常量所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。