OGeek|极客世界-中国程序员成长平台

标题: iphone - 键盘、方向和 UITextView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:24
标题: iphone - 键盘、方向和 UITextView

我有一个覆盖整个屏幕的 UITextview。为了补偿键盘,我添加了这个处理程序:

- (void)keyboardWasShownNSNotification*)aNotification{
    // Resize for the stupid keyboard
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    CGRect rect = _textView.frame;
    rect.size.height -= kbSize.height;
    _textView.frame = rect;

    CGPoint p = [_textView contentOffset];
    [_textView setContentOffset:p animated:NO];
    [_textView scrollRangeToVisible:NSMakeRange([_textView.text length], 0)];
}

这在纵向模式下很有效,但在横向模式下 View 完全消失了。有没有更优雅的解决方案来处理这个问题?我读过苹果keyboard management文档,但它对方向问题没有太多帮助。



Best Answer-推荐答案


所以,我不幸的解决方案是这样的

UIInterfaceOrientation o = [self interfaceOrientation];
if(o == UIInterfaceOrientationPortrait || o == UIInterfaceOrientationPortraitUpsideDown){
    rect.size.height -= kbSize.height;
}else if(o == UIInterfaceOrientationLandscapeLeft || o == UIInterfaceOrientationLandscapeRight){
    rect.size.height -= kbSize.width;
}

我想这是解决这个问题的唯一方法。不过,我仍然喜欢一个优雅的解决方案

关于iphone - 键盘、方向和 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5808092/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4