不推荐使用UIKeyboardBoundsUserInfoKey

时间:2011-07-15 06:47:17

标签: iphone objective-c

如何删除这些警告:

UIKeyboardCenterBeginUserInfoKey is deprecated

UIKeyboardCenterEndUserInfoKey is deprecated

UIKeyboardBoundsUserInfoKey is deprecated

我在这些陈述中得到了警告:

CGPoint beginCentre = [[[notification userInfo] valueForKey:UIKeyboardCenterBeginUserInfoKey] CGPointValue];

CGPoint endCentre = [[[notification userInfo] valueForKey:UIKeyboardCenterEndUserInfoKey] CGPointValue];

CGRect keyboardBounds = [[[notification userInfo] valueForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];

4 个答案:

答案 0 :(得分:5)

UIkeyboardboundsuserinfokey在IOS 6中不起作用..

使用UIKeyboardFrameBeginUserInfoKeyUIKeyboardFrameEndUserInfoKey密钥代替uikeyboardboundsuserinfokey

答案 1 :(得分:4)

简单:只是不要使用这些键。

如果您确实阅读了文档,它会告诉您应该使用UIKeyboardFrameBeginUserInfoKey和UIKeyboardFrameEndUserInfoKey。

答案 2 :(得分:3)

只需更改此

CGPoint beginCentre = [[[notification userInfo] valueForKey:UIKeyboardCenterBeginUserInfoKey] CGPointValue];

CGPoint endCentre = [[[notification userInfo] valueForKey:UIKeyboardCenterEndUserInfoKey] CGPointValue];

CGRect keyboardBounds = [[[notification userInfo] valueForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];

到这个

CGPoint beginCentre = [[[notification userInfo] valueForKey:@"UIKeyboardCenterBeginUserInfoKey"] CGPointValue];

CGPoint endCentre = [[[notification userInfo] valueForKey:@"UIKeyboardCenterEndUserInfoKey"] CGPointValue];

CGRect keyboardBounds = [[[notification userInfo] valueForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue];

看到区别?

 @"UIKeyboardBoundsUserInfoKey"

它适用于我

答案 3 :(得分:1)

任何标记为已弃用的内容意味着它可以(并且很可能将)在SDK的任何未来版本中删除。如果您忽略这些警告,那么在将来发布较新版本的SDK时,您的代码很可能无法运行。

如果您收到有关此问题的警告,请查看文档(如jtbandes建议的那样),这将为您提供有关使用内容的信息。