我已经搜遍了各种资料,但似乎找不到答案。最接近的是这里:UITextView cursor below frame when changing frame。
非常抱歉,由于我的声望(几乎)为零,无法提供截图证明,但它看起来与链接的SO帖子类似。
当我在iOS6上运行应用程序时,一切正常(内容随光标滚动以使其保持在屏幕上),但在iOS7上,光标超过了UITextView的末尾一行。 我尝试添加UIEdgeInsets来移动内容,但当用户正在输入文本时,它会不断添加新行,直到光标位于文本视图的末尾以下。
我的布局包括一个标签(headerText),下面是UITextView(textView)。 从选项卡栏中显示此视图。有一个键盘输入附件,但在调用函数之前,它的高度会自动计算到键盘高度中。
这是我用来调整视图大小的功能,从keyboard show/hide委托,旋转,初始布局等中调用:
非常抱歉,由于我的声望(几乎)为零,无法提供截图证明,但它看起来与链接的SO帖子类似。
当我在iOS6上运行应用程序时,一切正常(内容随光标滚动以使其保持在屏幕上),但在iOS7上,光标超过了UITextView的末尾一行。 我尝试添加UIEdgeInsets来移动内容,但当用户正在输入文本时,它会不断添加新行,直到光标位于文本视图的末尾以下。
我的布局包括一个标签(headerText),下面是UITextView(textView)。 从选项卡栏中显示此视图。有一个键盘输入附件,但在调用函数之前,它的高度会自动计算到键盘高度中。
这是我用来调整视图大小的功能,从keyboard show/hide委托,旋转,初始布局等中调用:
-(void)resizeViewsWithKbdHeight:(float)kbHeight
{
//set the header label frame
//set constraints
//total view width - 30 (15 each for left and right padding)
CGFloat labelWidth = ([[[self navigationController] view] bounds].size.width - 30);
CGSize constraintSize = {labelWidth, CGFLOAT_MAX};
//calculate needed height for header label
CGSize textSize = [[self headerText] sizeWithFont:[UIFont systemFontOfSize:17.0f]
constrainedToSize:constraintSize
lineBreakMode:NSLineBreakByWordWrapping];
//build and set frame for header label:
//make it the same as the old
CGRect headerTempSize = [[self headerLabel] frame];
//except for the height
headerTempSize.size.height = textSize.height;
//and set it
[[self headerLabel] setFrame:headerTempSize];
//correct the placement of the UITextView, so it's under the header label
//build a new frame based on current textview frame
CGRect newFrame = [[self textView] frame];
//get the y position of the uitextview, the +8 is the padding between header and uitextview
CGFloat vertPadding = [[self headerLabel] frame].origin.y + [[self headerLabel] frame].size.height + 8;
//bump it down vertically
newFrame.origin.y = vertPadding;
//bump things down by the amount of the navigation bar and status bar
float offscreenBump = [[[self navigationController] navigationBar] frame].origin.y + [[[self navigationController] navigationBar] frame].size.height;
//if we aren't showing the keyboard, add the height of the tab bar
if(kbHeight == 0) {
offscreenBump += [[[self tabBarController] tabBar] frame].size.height;
}
//calculate the new height of the textview, the +9 is for padding below the text view
CGFloat newHeight = [[[self navigationController] view] bounds].size.height - ([[self textView] frame].origin.y + 9 + kbHeight + offscreenBump);
//resize the height as calculated
newFrame.size.height = newHeight;
//set textview frame to this new frame
[[self textView] setFrame:newFrame];
}
我正在尝试支持iOS5,因此不能使用自动布局。
可能我对我的做法过于天真。
提前感谢!