升级了xcode5, 适配ios7. 各种坑爹问题..
今天又碰到了一个。
textview的高度无法正确计算.(之前可以通过textView.contentSize.height来获取一个float类型的高度)
但是在ios7上,发现这玩意不管用了。
调试了好多遍,发现打印出来的结果都是最早设置的frame高度。 无法动态改变。
蛋疼的。
后来找了一遍,才发现一种解决办法。
if (isIos7System)
{
CGRect txtFrame = textview.frame;
textview.frame = CGRectMake(0,65+imageview.frame.size.height,320,txtFrame.size.height =[[NSString stringWithFormat:@"%@\n ",textview.text]
boundingRectWithSize:CGSizeMake(txtFrame.size.width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:[NSDictionary dictionaryWithObjectsAndKeys:textview.font,NSFontAttributeName, nil] context:nil].size.height);
textview.frame = CGRectMake(0,65+imageview.frame.size.height,320,txtFrame.size.height);
[self.view addSubview:textview];
}
这样就能获取textview的高度。
另外。isIos7System是个宏定义,
#define isIos7System [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0
iOS7下TextView高度计算问题解决方案
本文讨论了在iOS7环境下使用Xcode5时,遇到的TextView高度无法正确计算的问题,并提供了一种通过判断是否为iOS7系统来动态调整TextView frame的方法。此方法能够获取TextView的实际高度,解决了开发中的困扰。
1697

被折叠的 条评论
为什么被折叠?



