Zig*_*rth 8 iphone keyboard height uikeyboard ios
我知道我可以从键盘上的UIKeyboardFrameEndUserInfoKey获取UIKeyboard高度,并在它成为第一响应者时触发keyboardDidShow通知.
但是,我想知道在这些事件之前键盘的预期高度,所以我可以在视图控制器的viewDidLoad上设置某些设计元素.
由于设备正在改变并且新的拼写校正条改变了键盘高度,我不想硬编码高度.
有没有人知道如何从键盘获得预期的高度考虑到它是否有自动纠正等?
您可以通过以下方式进行:
- (void)viewDidLoad {
[super viewDidLoad];
[self initializeTextView];
Run Code Online (Sandbox Code Playgroud)
} -(void)初始化TextView{
// Listen for keyboard appearances and disappearances
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
myColoredTextview = [[UITextView alloc]initWithFrame:CGRectMake(0, 20, 300, 100)];
myColoredTextview.delegate = self;
[self.view addSubview:myColoredTextview];
myColoredTextview.backgroundColor = [UIColor lightGrayColor];
}
- (void)keyboardDidShow: (NSNotification *) notif{
// Do something here
NSLog(@"show:%@",notif);
NSDictionary *userInfo = [notif valueForKey:@"userInfo"];
CGRect kbFrame = [[userInfo objectForKey:@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue];
NSLog(@"keboardHeight:%f",kbFrame.size.height);
Run Code Online (Sandbox Code Playgroud)
}
- (void)keyboardDidHide: (NSNotification *) notif{
// Do something here
NSLog(@"hide:%@",notif);
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
1077 次 |
| 最近记录: |