【问题标题】:UIScrollView scroll problemUIScrollView 滚动问题
【发布时间】:2010-06-15 21:21:56
【问题描述】:

我有一个 UIScrollView 并且在屏幕的下部是一个文本字段。当我选择文本字段时,键盘显示在文本字段上方。 UIScrollView 中的 UIView 不够大,无法向上滚动并为键盘腾出一些空间。所以我尝试以编程方式放大 UIView。 这就是我所拥有的:

- (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 point = CGPointMake(0, 450);
[scrollView setContentOffset: point animated: YES];

return YES;
}

谢谢。

【问题讨论】:

    标签: iphone uiscrollview


    【解决方案1】:

    您可以注册以在您的视图控制器中接收UIKeyboardWillShowNotification。然后将视图控制器的视图框架向上移动通知中提供的键盘大小。

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

    对 UIKeyboardWillHideNotification 执行相反的操作。

    【讨论】:

      猜你喜欢
      • 2015-10-27
      • 1970-01-01
      • 2013-08-01
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 2011-03-19
      相关资源
      最近更新 更多