无法获取 UIKeyboardFrameEndUserInfoKey 的横向值
Can't get landscape value for UIKeyboardFrameEndUserInfoKey
在 iOS 8 之前,我可以使用 UIKeyboardBoundsUserInfoKey 来获取键盘信息。
NSValue *value = [info objectForKey:UIKeyboardBoundsUserInfoKey];
我知道它已经贬值了,从 iOS 8 开始它就不再有效了。我尝试使用 UIKeyboardFrameEndUserInfoKey,但它似乎 return 即使在横向中也是纵向值。当我在 iOS 7 上 NSLog(@"%@", [info objectForKey:UIKeyboardBoundsUserInfoKey]);
时,它会记录 NSRect: {{0, 0}, {162, 568}}
但是当我 NSLog(@"%@", [info objectForKey:UIKeyboardFrameEndUserInfoKey]);
时它会记录 NSRect: {{0, 0}, {568, 162}}
有人知道在 iOS 8 上工作的 valueForKey 会 return 横向模式下的信息吗?还是 "swap" [info objectForKey:UIKeyboardFrameEndUserInfoKey] 中的数值使其横向显示的方法?
非常感谢您!
根据docs关于UIKeyboardFrameEndUserInfoKey
,
These coordinates do not take into account any rotation factors
applied to the window’s contents as a result of interface orientation
changes. Thus, you may need to convert the rectangle to window
coordinates (using the convertRect:fromWindow: method) or to view
coordinates (using the convertRect:fromView: method) before using it.
因此,在将矩形存储为 CGRect
或 NSValue
之前,请尝试将其转换为视图坐标,例如:
CGRect rect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect convertedRect = [self.view convertRect:rect fromView:nil];
NSValue *value = [NSValue valueWithCGRect:convertedRect];
在 iOS 8 之前,我可以使用 UIKeyboardBoundsUserInfoKey 来获取键盘信息。
NSValue *value = [info objectForKey:UIKeyboardBoundsUserInfoKey];
我知道它已经贬值了,从 iOS 8 开始它就不再有效了。我尝试使用 UIKeyboardFrameEndUserInfoKey,但它似乎 return 即使在横向中也是纵向值。当我在 iOS 7 上 NSLog(@"%@", [info objectForKey:UIKeyboardBoundsUserInfoKey]);
时,它会记录 NSRect: {{0, 0}, {162, 568}}
但是当我 NSLog(@"%@", [info objectForKey:UIKeyboardFrameEndUserInfoKey]);
时它会记录 NSRect: {{0, 0}, {568, 162}}
有人知道在 iOS 8 上工作的 valueForKey 会 return 横向模式下的信息吗?还是 "swap" [info objectForKey:UIKeyboardFrameEndUserInfoKey] 中的数值使其横向显示的方法? 非常感谢您!
根据docs关于UIKeyboardFrameEndUserInfoKey
,
These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.
因此,在将矩形存储为 CGRect
或 NSValue
之前,请尝试将其转换为视图坐标,例如:
CGRect rect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect convertedRect = [self.view convertRect:rect fromView:nil];
NSValue *value = [NSValue valueWithCGRect:convertedRect];