2013-04-28 105 views
2

我有一个UITextView,可以旋转,调整大小拖动等,一切工作正常在iOS 6和iOS 5时调整大小或旋转或拖动,但当我旋转UITextView然后调整以下结果出现:更改UITextView的字体大小后旋转奇怪的iOS 5

enter image description here

有在TextView中没有换行,现在,它工作正常在iOS 6 enter image description here

对于旋转我使用的是:

- (void)rotation:(CGFloat)newAngle { 
    self.transform = CGAffineTransformMakeRotation(newAngle * M_PI/180); 
} 

并调整大小我计算宽度用户已设置新的字体大小和设置使用范围:

CGSize newFrameSize = [self sizeThatFits:CGSizeMake([[self getLongestStringInTextView] sizeWithFont:self.font].width + 30, CGFLOAT_MAX)]; 
self.bounds = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, newFrameSize.width, newFrameSize.height); 

我知道它有边界问题,但我不知道什么是错的,或者如果我做什么都不对

+0

但是,你为什么要设置绑定?可能有像sizeToFit这样的方法。 – Iducool 2013-04-28 11:35:49

+0

在这里,你可以使用框架而不是边界 – Iducool 2013-04-28 11:38:15

+0

我得到的设置框架和中心点的相同结果和框架也不适用于iOS 6. sizeToFit做同样的事情,我也做,它也不适用于多行UITextView – Efesus 2013-04-28 12:20:03

回答

0

好的,我修好了。

我们有一个国际志愿者组织观察员界

[self addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionOld context:NULL]; 

跟踪范围的更改,并设置边界来CGRectZero

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 
    if ([keyPath isEqualToString:@"bounds"]) { 
     [self removeObserver:self forKeyPath:@"bounds"]; 

     CGRect bounds = self.bounds; 
     self.bounds = CGRectZero; 
     self.bounds = bounds; 

     [self addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionOld context:NULL]; 
    } 
} 

其在iOS 6中工作正常,但不会在iOS 5,这得到了固定通过也设置框架CGRectZero

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 
    if ([keyPath isEqualToString:@"bounds"]) { 
     [self removeObserver:self forKeyPath:@"bounds"]; 

     CGRect bounds = self.bounds; 
     CGRect frame = self.frame; 
     self.frame = CGRectZero; 
     self.bounds = CGRectZero; 
     self.frame = frame; 
     self.bounds = bounds; 

     [self addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionOld context:NULL]; 
    } 
}