简体   繁体   English

iOS 7.1中的UITextView垂直对齐

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM