2014-10-20 2 views
0

키보드가 텍스트를 숨기는 것을 방지하기 위해 이전 버전의 iOS에서 올바르게 작동하는 다음 코드를 사용하고 있습니다. iOS 8에서는 아무 일도 일어나지 않습니다.iOS 8 키보드가 표시 될 때 UITextView가 슬라이딩되지 않음

- (BOOL)textViewShouldBeginEditing:(UITextView*)textView {   
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 

    CGRect frame = self.view.bounds; 
    frame.size.height = frame.size.height - [Application keyboardHeight]; 
    noteView.frame = frame; 
    [UIView commitAnimations]; 

    return YES; 
} 


- (void)textViewDidEndEditing:(UITextView *)textView { 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.1]; 

    noteView.frame = self.view.bounds; 
    [UIView commitAnimations]; 
} 

어쩌면 나는 바보 같은 것을 놓치고 있지만, 무슨 일이 일어나고 있는지 이해할 수 없습니다.

답변

1

이 방법은 다른 방식으로 접근하며 iOS8에서 잘 작동하는 것으로 보입니다. 이 예제하여 UITextView이 대답 경우

- (void) keyboardWillShow:(NSNotification *) notification { 

    CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
    CGSize size = self.view.frame.size; 

    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) 
     textView.frame = CGRectMake(0, 0, size.width , size.height - keyboardSize.height + 50) ; 
    else  
     textView.frame = CGRectMake(0, 0, size.width , size.height - keyboardSize.width + 50) ; 
} 

- (void) keyboardWillHide:(NSNotification *) notification { 
    #pragma unused(notification) 

    textView.frame = CGRectMake(0, 0, self.view.frame.size.width , self.view.frame.size.height) ; 
} 

확실하지 키보드를 표시 및 숨기기 처리 할 수 ​​

- (void) viewDidLoad 
{ 
    //Do other stuff 

    // listen for keyboard 
    [[NSNotificationCenter defaultCenter] addObserver:self 
        selector:@selector(keyboardWillShow:) 
         name:UIKeyboardWillShowNotification 
         object:nil]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
        selector:@selector(keyboardWillHide:) 
         name:UIKeyboardWillHideNotification 
         object:nil]; 
} 

그리고 다음이 방법을 사용할 수있는 공간을 차지 볼 수 있지만 그렇게 대답으로 게시됩니다 코드가 형식화됩니다. 그것이 모두 똑같이 도움이되기를 바랍니다.

0

[응용 프로그램 keyboardHeight]가 반환하는 항목이 확실하지 않지만 비슷한 문제가 있으며 문제가 무엇인지 알아 냈습니다. @RobCroll에서 사용하는 것과 동일한 알림 방법을 사용하는 경우 iOS7 이전 버전에서는 가로 방향으로 keyboardSize.width를 사용해야했습니다. 그러나 iOS8에서 Apple은 마침내이 버그를 고쳤으며 가로 방향으로 keyboardSize.height를 사용해야합니다! 아마도 귀하의 [Application keyboardHeight]도 여전히 keyboardSize.width를 사용합니까?

관련 문제