2
我有一個tableview需要用於添加內容的子視圖。子視圖包含用於輸入文本的UITextView。在此之前7.1以下會發生:更新到iOS 7.1後動態textView調整大小破壞
- 子視圖通過scrollViewDidScroll
- 激活時粘在的tableview的底部,鍵盤將顯示,視圖與鍵盤動畫了
- 當文本鍵入,如果需要textView將向上擴展,textView的底部保持原位。
NOW 7.1後,以下行爲發生:
- 子視圖向上的鍵盤精細
- 如果文本強制新行動畫,而不是擴大,textViewDidEndEditing GET就會觸發這個和鍵盤解散。
- 在textview中不允許進一步編輯,任何編輯都會使鍵盤立即消失。
任何有關什麼改變與7.1會使現有的,工作代碼中斷的建議?這裏是所有相關的代碼。我很樂意提供任何額外的細節。我已經有一段時間了,這讓我精神振奮。
tableViewController.m - 在子視圖中添加的代碼。子視圖有它自己的xib。 xib是在IB中創建的。我刪除了與其他組件有關的部分。
- (void)viewDidLoad {
//Setup contentBar
if (self.contentBar == nil) {
//Add subView to View
NSArray *subviewArray = [[NSArray alloc] init];
subviewArray = [[NSBundle mainBundle] loadNibNamed:contentIdentifier owner:self options:nil];
self.contentBar = [subviewArray objectAtIndex:0];
[self.view addSubview:self.contentBar];
//Setup textView
UITextView *addContentTextView = (UITextView *)[self.contentBar viewWithTag:2];
addContentTextView.text = [NSString stringWithFormat:@"text (optional)"];
addContentTextView.delegate = self;
}
}
我的TextView代表
#pragma mark - TextView Delegate
- (void)textViewDidEndEditing:(UITextView *)textView{
NSLog(@"textViewDidEndEditing:");
if ([textView.text isEqualToString:@""]) {
textView.text = @"text (optional)";
textView.textColor = [UIColor lightGrayColor]; //optional
}
[textView resignFirstResponder];
}
- (void)textViewDidBeginEditing:(UITextView *)textView {
NSLog(@"textViewDidBeginEditing:");
if ([textView.text isEqualToString:@"text (optional)"]) {
textView.text = @"";
textView.textColor = [UIColor blackColor]; //optional
}
[textView becomeFirstResponder];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
if ([newText length] > 0 || _image) {
_addContentButton.enabled = YES;
} else {
_addContentButton.enabled = NO;
}
if([text isEqualToString:[text stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]]) {
return YES;
} else {
NSLog(@"return pressed");
[textView resignFirstResponder];
[self addedContent:nil];
}
return YES;
}
- (void)textViewDidChange:(UITextView *)textView
{
NSLog(@"textViewDidChange");
[self sizeTextView];
}
- (void)sizeTextView
{
NSLog(@"sizeTextView");
UIImageView *barImage = (UIImageView *)[self.contentBar viewWithTag:87];
UITextView *textView = (UITextView *)[self.contentBar viewWithTag:2];
CGSize sizeThatShouldFitTheContent = [textView sizeThatFits:textView.frame.size];
CGRect newTextViewFrame = textView.frame;
newTextViewFrame.size.height = sizeThatShouldFitTheContent.height;
CGFloat adjustment = sizeThatShouldFitTheContent.height - textView.frame.size.height;
newTextViewFrame.origin.y = textView.frame.origin.y - adjustment;
textView.frame = newTextViewFrame;
CGRect newImageViewFrame = barImage.frame;
newImageViewFrame.size.height = barImage.frame.size.height + adjustment;
newImageViewFrame.origin.y = barImage.frame.origin.y - adjustment;
barImage.frame = newImageViewFrame;
}
如果你想看看別的,我會很高興將它張貼。