質問

I have a UIPopover with a UIScrollViewinside it that contains a UITextView at the bottom. When the keyboard shows, the popover is resized as the text view begins to be edited. I want the code below to ensure the text view is visible:

- (void)textViewDidBeginEditing:(UITextView *)textView {

    CGRect visRect = textView.frame;
    [self.scrollView scrollRectToVisible:visRect animated:NO];

}

The problem is that the code does not make the entire text view visible. Instead, only the text view up to the bottom of the cursor is shown, as shown below:

enter image description here

How can I show the entire text view/ scroll the scrollview to the bottom? I have tried this:

CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
[self.scrollView setContentOffset:bottomOffset animated:YES];

as explained in this answer but nothing works.

In addition, my scrollview is scrolled to the position shown AFTER the keyboard is moved into place. Ideally I'd like the scrolling to happen before or during the keyboard movement.

Any help would be great.

役に立ちましたか?

解決 2

I found the solution:

- (void)keyboardDidShow:(NSNotification *)notification {
NSLog(@"Notification: %s", __PRETTY_FUNCTION__ );
//
CGFloat textviewBottom = CGRectGetMaxY(self.commentsTextView.frame);
CGRect belowTextViewRect = CGRectMake(0, textviewBottom, 350.f, self.scrollView.contentSize.height - textviewBottom);
// NB! This works ONLY: 1) keyboardDidShow 2) Non-animated;
// Does NOT work: 1) animated, 2) keyboardWillShow, 3) textViewDidBeginEditing
[self.scrollView scrollRectToVisible:belowTextViewRect animated:NO];
}

他のヒント

@hey Dave

This By default Case in of UIPopOverController, whenever we used UIPopOverControler to display any PopUpView and in suppose that PopUpView height as large as can be covered by KeyBoard then in that case that PopOverView Automatically gets Shrink itself.as you resign keyboard that PopUpView will expand itself automatically.I have faced same case.

This is just my opinion , you can change the origin of CurrentView(parentView of PopUpView) as keyboard going to display/hide so that PopUpView could display itself properly from and could get the appropriate space.

See Below Are the Delegate methods of UITextView Responds Back as editing start and end.

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
 //chnage the OriginY of PopUpView's SUperView
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{  
 //re Adjust the OriginY of PopUpView's SUperView
}

I hope it may helpful to you.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top