开发者

UIScrollView scroll problem

I have an UIScrollView and in the lower part of the screen is a textfield. When I select the textfield the keyboard is displayed above the textfield. The UIView within the UIScrollView is not large enough to scroll up and free some space for the keyboard. So I've tried to enlarge the UIView programaticly. This is what I've got:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {


UIScrollView *scrollView = (UIScrollView *)[[self view] viewWithTag: 2];
UIView *contentview = [[self view] viewWithTag: 3];

CGRect rect = contentview.frame;

rect.size.height = 650;
contentview.frame = rect;

[scrollView setContentSize: contentview.frame.size];

//first try
rect.origin.y = 450;
[scrollView scrollRectToVisible: rect animated: YES]; 

//second try
CGPoint poin开发者_Python百科t = CGPointMake(0, 450);
[scrollView setContentOffset: point animated: YES];

return YES;
}

thanks.


You can register to receive the UIKeyboardWillShowNotification in your view controller. Then move the view controller's view frame up by the size of the keyboard which is provided in the notification.

CGRect frame = self.view.frame;
frame.origin.y -= keyboard.size.height;
self.view.frame = frame;

Do the opposite for UIKeyboardWillHideNotification.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜