
UITextView cursor below frame when changing frame
对不起,没有截图,因为我(几乎)没有声誉,但它看起来类似于链接的SO帖子.
当我在iOS6上运行应用程序时,工作完美(内容滚动光标以将其保留在屏幕上),但在iOS7上,光标超出了UITextVIEw的末尾.我尝试添加UIEdgeInsets来移动内容,但是当用户主动输入文本时,它只是不断添加新行,直到光标位于文本视图的末尾.
我的布局包含一个Label(headerText),下面有一个UITextVIEw(textVIEw).此视图显示在选项卡栏中.添加了一个键盘输入附件,但在调用该功能之前,它的高度会自动计算到键盘高度.
这是我用来调整视图大小的函数,从键盘显示/隐藏委托,旋转,初始布局等调用:
-(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,所以没有autoLayout.
我有可能对我的工作方式非常天真.
提前致谢!
解决方法 这似乎是iOS 7中的一个错误.我发现纠正这个问题的唯一方法是为UITextVIEw添加一个委托并实现textVIEwDIDChangeSelection,重置视图以显示如下选择:#define SYstem_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)- (voID) textVIEwDIDChangeSelection: (UITextVIEw *) tVIEw { if (SYstem_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { [tVIEw scrollRangetoVisible:[tVIEw selectedRange]]; }} 总结 以上是内存溢出为你收集整理的ios – UITextView外的光标全部内容,希望文章能够帮你解决ios – UITextView外的光标所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)