블로그 이미지
뚜뚜♥

카테고리

분류 전체보기 (18)
작업 (0)
프로그램 (2)
생활 (14)
Total9,047
Today2
Yesterday4

'2012/11'에 해당되는 글 1건

  1. 2012.11.14 keyboard가 나타날때 View이동

 .m [viewDidLoad에]

 //뷰 올리고 내리기(화면이 뜨자마자 등록시켜주는것

[[NSNotificationCenter defaultCenter] addObserver:self

                                            selector:@selector(keyboardWillAnimate:)

                                            name:UIKeyboardWillShowNotification //키보드가 올라왔을때keyboardWillAnimate를 실행

                                            object:nil];

    

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardWillAnimate:)

                                             name:UIKeyboardWillHideNotification  //들어갈때

                                             object:nil];



//keyboard가 올라가면 이 메소드가 실행되야 하기때문에 viewDidLoad밖에 선언

- (void)keyboardWillAnimate:(NSNotification *)notification

{

    NSLog(@"keyboardWillAnimate"); //Test Log

    

    CGRect keyboardBounds;

    [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardBounds];

    NSNumber *duration = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];

    NSNumber *curve = [notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];

    

    keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:[duration doubleValue]];

    [UIView setAnimationCurve:[curve intValue]];

    if([notification name] == UIKeyboardWillShowNotification)

    {

        [self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - keyboardBounds.size.height, self.view.frame.size.width, self.view.frame.size.height)];

    }

    else if([notification name] == UIKeyboardWillHideNotification)

    {

        [self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + keyboardBounds.size.height, self.view.frame.size.width, self.view.frame.size.height)];

    }

    [UIView commitAnimations];

}


//Notification해제

- (void)_removeKeyboardNotification

{

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];

}

'프로그램 > iPhone' 카테고리의 다른 글

keyboard가 나타날때 View이동  (0) 2012.11.14
Keyboard return  (0) 2012.07.31
Posted by EUNJINI 뚜뚜♥

최근에 달린 댓글

최근에 받은 트랙백

글 보관함