UITextView не изменяет размер при появлении клавиатуры при загрузке из cotroller панели вкладок

I have a simple view controller (SecondViewController) used to manage a UITextview (I'm building a simple editor) this is the code of the SecondViewController.h


    @interface SecondViewController : UIViewController {
 IBOutlet UITextView *textView;
}
@property (nonatomic,retain) IBOutlet UITextView *textView;
@end
and this is the SecondViewController.m

// // EditorViewController.m // Editor // // Created by elio d'antoni on 13/01/11. // Copyright 2011 none. All rights reserved. // @implementation SecondViewController @synthesize textView;

/* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"uiViewBg.png"]]; textView.layer.borderWidth=1; textView.layer.cornerRadius=5; textView.layer.borderColor=[[UIColor darkGrayColor] CGColor]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillDisappear:) name:UIKeyboardWillHideNotification object:nil];

}

-(void) matchAnimationTo:(NSDictionary *) userInfo { NSLog(@"match animation method"); [UIView setAnimationDuration:[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; [UIView setAnimationCurve:[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]]; }

-(CGFloat) keyboardEndingFrameHeight:(NSDictionary *) userInfo { NSLog(@"keyboardEndingFrameHeight method");

CGRect keyboardEndingUncorrectedFrame = 

[[ userInfo objectForKey:UIKeyboardFrameEndUserInfoKey ] CGRectValue]; CGRect keyboardEndingFrame = [self.view convertRect:keyboardEndingUncorrectedFrame fromView:nil]; return keyboardEndingFrame.size.height; }

- (CGRect) adjustFrameHeightBy: (CGFloat) изменить multipliedBy: (NSInteger) direction {NSLog (@ "adjust method");

return CGRectMake(20, 
                  57, 
                  self.textView.frame.size.width, 
                  self.textView.frame.size.height + change * direction);

} - (void) keyboardWillAppear: (NSNotification *) notification {NSLog (@ "keyboard появляться"); [UIView beginAnimations: nil context: NULL]; [self matchAnimationTo: [userInfo уведомления]]; self.textView.frame = [self adjustFrameHeightBy: [self keyboardEndingFrameHeight: [userInfo уведомления]] multipliedBy: -1]; [UIView commitAnimations]; } - (void) keyboardWillDisappear: (NSNotification *) уведомление {NSLog (@ "keyboard исчезнуть"); [UIView beginAnimations: nil context: NULL]; [self matchAnimationTo: [userInfo уведомления]]; self.textView.frame = [self adjustFrameHeightBy: [self keyboardEndingFrameHeight: [userInfo уведомления]] multipliedBy: 1]; [UIView commitAnimations]; }

// Переопределить, чтобы разрешить ориентацию, отличную от портретной ориентации по умолчанию. - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {return YES; }

  • (void) didReceiveMemoryWarning {// Освобождает представление, если оно не имеет супервизора. [super didReceiveMemoryWarning];

    // Освобождаем все кэшированные данные, изображения и т. Д., Которые не используются. }

  • (void) viewDidUnload {// Освободить все оставшиеся подвиды основного представления. // например self.myOutlet = ноль; }

  • (void) dealloc {[супер-освобождение]; }

@end

проблема в том, что при загрузке контроллера представления из контроллера панели вкладок textView не изменяет размер при появлении клавиатуры, но ЖЕ код работает, если загружен как приложение на основе одного представления. Надеюсь, я был достаточно ясен. Я использовал шаблон tabBar, предоставленный xcode, без изменений.


person oiledCode    schedule 15.01.2011    source источник


Ответы (1)


Ваш код выглядит правильно, вы заметили, что вы не выпускаете textView в dealloc и viewDidUnload, но это должно иметь какое-то значение.

Я бы проверял, получены ли уведомления и все подключено, т.е. textView не равен нулю

person railwayparade    schedule 16.01.2011
comment
Моя вина! проблема была в построителе интерфейса, спасибо за ваш ответ - person oiledCode; 17.01.2011