iOS2012. 10. 4. 11:23

UITextField가 존재하는 뷰의 viewWillDisappear 또는 viewDidDisappear 메소드에서

[self.view endEditing:YES];

을 호출하면 해당 키보드가 내려간다.


resignFirstResponder도 물론 가능하다. 하지만 UITextField 객체가 멤버 변수로 선언 되어 있지 않을 경우

유용할 듯..

Posted by 다오나무
iOS2012. 9. 28. 09:59

  1. - (void) animateTextField: (UITextField*) textField up: (BOOL) up{
  2. int txtPosition = (textField.frame.origin.y - 140);
  3. const int movementDistance = (txtPosition < 0 ? 0 : txtPosition); // tweak as needed
  4. const float movementDuration = 0.3f; // tweak as needed
  5.  
  6. int movement = (up ? -movementDistance : movementDistance);
  7.  
  8. [UIView beginAnimations: @"anim" context: nil];
  9. [UIView setAnimationBeginsFromCurrentState: YES];
  10. [UIView setAnimationDuration: movementDuration];
  11. self.view.frame = CGRectOffset(self.view.frame, 0, movement);
  12. [UIView commitAnimations];
  13. }
  14.  
  15. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  16. [self animateTextField: textField up: YES];
  17. }
  18.  
  19. - (void)textFieldDidEndEditing:(UITextField *)textField{
  20. [self animateTextField: textField up: NO];
  21. }
  22.  
  23. - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  24. [theTextField resignFirstResponder];
  25. return YES;
  26. }

Posted by 다오나무
iOS2012. 9. 24. 11:45

리턴키 타입을 Done으로 변경


textField.returnKeyType = UIReturnKeyDone

Posted by 다오나무
영삼이의 IT정보2012. 6. 10. 17:08

- (void) viewDidLoad 에서

scrollView.contentSize = self.view.frame.size;

선언 이후 화면 변환(키보드 등장)에 대한 노티피케이션 감시 코드 추가

1) viewWillAppear 에서 UIKeyboardDidShowNotification 과 UIKeyboardDidHideNotification 등록

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];


-(void)keyboardDidShow:(NSNotification *)notif 
{
//키보드를 여러 객체들이 열 수 있는데, 자신의 키보드에만 반응하기 위해서, 이 정보를 갖고 있어야 한다
  if(keyboradVisible) 
  { return; }
  NSDictionary* info = [notif userInfo];
  NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
  CGSize keyboardSize = [aValue CGRectValue].size;

  CGRect viewFrame = self.view.frame;
  viewFrame.size.height -= keyboardSize.height;

  scrollView.frame = viewFrame;
  keyboardVisible = YES;
}

-(void)keyboardDidhide:(NSNotification *)notif 
{
  if(!keyboardVisible)
  { return; }

  NSDictionary *info = [notif userInfo];
  NSValue *aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
  CGSize keyboardSize = [aValue CGRectValue].size;

  CGRect viewFrame = self.view.frame;
  viewFrame.size.height += keyboardSize.height;

  scrollView.frame = viewFrame;
  
  keyboardVisible = NO;
  
}

2) viewWillDisappear 에서 등록 해지

[[NSNotificationCenter defaultCenter
] removeObserver:self]



'영삼이의 IT정보' 카테고리의 다른 글

Tabbar 아이콘  (0) 2012.06.11
StoreKit  (0) 2012.06.10
아이폰 OS 개발 자료 총정리  (2) 2012.06.04
UIImageJPEGRepresentation  (0) 2012.06.04
XHTML/CSS 무료 템플릿 배포사이트  (0) 2012.06.01
Posted by 다오나무