[英]UITextView Vertical Alignment in iOS 7.1
I used this codes in my app to align my textView
vertically center and it was working until iOS 7.1
. 我在应用程序中使用此代码将textView
垂直居中对齐,直到iOS 7.1
。
I guess contentSize
property is changed in iOS 7.1
how can you help me with that? 我猜iOS 7.1
contentSize
属性已更改,您如何帮助我呢?
[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};
}
我有同样的问题,对我[tv sizeThatFits:tv.bounds.size].height
是使用[tv sizeThatFits:tv.bounds.size].height
而不是tv.contentSize.height
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.