2

我在我的应用程序中使用了这个代码来对齐我的textView垂直中心,它一直工作到iOS 7.1.

我想contentSize财产发生了变化,iOS 7.1 你怎么能帮我解决这个问题?

    [textView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:    (NSDictionary *)change context:(void *)context
{
UITextView * tv = object;
CGFloat topCorrect = (tv.bounds.size.height - tv.contentSize.height * tv.zoomScale) / 2.0;
topCorrect = (topCorrect < 0 ? 0 : topCorrect);
tv.contentOffset = (CGPoint) {.x = tv.contentOffset.x, .y = - topCorrect};
}
4

1 回答 1

3

我遇到了同样的问题,对我有用的是使用 [tv sizeThatFits:tv.bounds.size].height而不是 tv.contentSize.height

于 2014-03-24T15:55:28.330 回答