我在我的应用程序中使用了这个代码来对齐我的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};
}