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但似乎没有任何工作.
提前致谢
解决方法 由于代码中任何地方都存在不推荐使用的常量会引发警告(并打破我们-Werror用户的构建),您可以使用实际的常量值来查找字典.感谢Apple通常(总是?)使用常量名称作为它的值.至于运行时检查,我认为你更好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中不推荐使用的常量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)