gpt4 book ai didi

iphone - 键盘、方向和 UITextView

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:19:13 25 4
gpt4 key购买 nike

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

- (void)keyboardWasShown:(NSNotification*)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文档,但它没有提供太多关于方向问题的信息。

最佳答案

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com