如何根据目标c中的内容调整textview以及工具栏的大小

开发商

我使用了以下代码,但无法获得结果

CGRect newFrame = _text_view.frame;
CGRect newToolbarFrame = self.navigationController.toolbar.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);

从上面的代码中,请让我知道什么是newsize?

贾德普·纳格拉(Jaideep Nagra)

为了根据内容向上扩展textview的高度,我使用gitHub项目。

为了简单地更改文本视图的位置,使其保持在键盘上方,请尝试以下操作

// First add these
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

然后在这些方法中,执行此操作

- (void) keyboardWillShow:(NSNotification *)note {

    //Get keyboard size and loctaion
    CGRect keyboardBounds;
    [[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];

    // get a rect for the textView frame
    CGRect containerFrame = _text_view.frame;

    // Provided you keep fixed number of maximum lines
    containerFrame.origin.y = self.view.bounds.size.height - (keyboardBounds.size.height + containerFrame.size.height);

    // set views with new info
    _text_view.frame = containerFrame;

    // Change toolbar location as per it's height
    _tool.frame=CGRectMake(0, 
                           _text_view.frame.origin.y - _tool.frame.size.height, 
                           _tool.frame.size.width,
                           _tool.frame.size.height);

}

- (void) keyboardWillHide:(NSNotification *)note{

    CGRect keyboardBounds;
    [[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];

    // get a rect for the textView frame
    CGRect containerFrame = _text_view.frame;
    containerFrame.origin.y = self.view.bounds.size.height - containerFrame.size.height;

    // set views with new info
    _text_view.frame = containerFrame;

    // Similarly again change toolbar location
}

或者,您可以简单地将textview保留在scrollView中,并在键盘显示时更改滚动视图的插图。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Android中创建可调整大小的工具栏(或ActionBar)

如何根据目标 c 中的文本内容调整标签高度

如何在开始目标中隐藏工具栏

如何通过CoordinatorLayout将TextView移到工具栏中?

如何修复工具栏中的CircularProgressIndicator()大小

如何设置工具栏按钮的大小

PreferenceActivity中的内容经过工具栏

在iOS8中旋转时调整工具栏的大小

自动调整jQuery工具栏的大小并对齐它

根据窗口大小调整div以及内部内容的大小

如何在Android中的棒棒糖设备中调整工具栏的高度

如何根据QScrollArea中的子内容自动调整QVBoxLayout的大小?

如何调整 2 个工具栏以适合父宽度

工具栏中定义的textview中的当前位置

如何访问工具栏中的按钮?

如何删除工具栏中的设置?

Android折叠工具栏:如何调整文本大小,以使其显示全文而不是部分文字

如何必须根据内容调整大小的部分以及使用剩余空间的部分

从android中的Fragment访问工具栏textview

如何在Ubuntu 14.04中为工具栏使用22像素大小的图标

如何在tinyMCE中添加字体大小的工具栏?

如何使工具栏不与Android中的其他内容重叠?

在Android中向上滚动内容时如何隐藏工具栏

如何更改工具栏的文字大小?

在工具栏中更改标题的颜色和大小-Android

如何删除Eclipse工具栏中的启动配置栏?

如何让我的搜索栏覆盖工具栏中的标题?

Windows 8 ui所有窗口模糊,图标大小随机(以及工具栏)

如何使用折叠工具栏将工具栏固定在协调器布局中?