Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios scrollView.setContentOffset根本不滚动视图_Ios_Uiscrollview - Fatal编程技术网

Ios scrollView.setContentOffset根本不滚动视图

Ios scrollView.setContentOffset根本不滚动视图,ios,uiscrollview,Ios,Uiscrollview,我一直在关注和其他一些教程/博客等,试图让我的视图在用户点击“return”并在键盘覆盖的UITextField上结束时滚动,但实际上什么都不起作用 我想知道是什么原因导致了这一切 基本上: 用户希望在应用程序中执行某些操作:添加信用卡 显示包含所有CC字段的UIView 1/2的UITextFields由键盘覆盖 当用户到达时滚动视图 什么都没有发生。正在点击并执行用于检测“键盘覆盖”案例的代码,但:[self.scrollView setContentOffset:scrollPoint

我一直在关注和其他一些教程/博客等,试图让我的视图在用户点击“return”并在键盘覆盖的UITextField上结束时滚动,但实际上什么都不起作用

我想知道是什么原因导致了这一切

基本上:

  • 用户希望在应用程序中执行某些操作:添加信用卡
  • 显示包含所有CC字段的UIView
  • 1/2的UITextFields由键盘覆盖
  • 当用户到达时滚动视图
什么都没有发生。正在点击并执行用于检测“键盘覆盖”案例的代码,但:
[self.scrollView setContentOffset:scrollPoint动画:是]
完全无效

想法

显示屏幕截图:

代码:与链接中的教程相同。没有什么新鲜事

试试这个

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView animateWithDuration:0.25 animations:^{

     [yourTextField setFrame:CGRectMake(yourTextField.frame.origin.x, yourTextField.frame.origin.y-keyboardHeight, yourTextField.frame.size.width, yourTextField.frame.size.height)];
   }];
} 


为了避免文本字段被键盘覆盖,我要做的是,当用户触摸文本字段时,将其设置为屏幕顶部的动画,以开始使用键盘输入内容,并在完成后将其设置为动画。在我看来,它要优雅得多。也许这是你的另一个解决方案。。。我为不同的屏幕大小和不同的数字。。。你可能需要调整它当然

因此,请听textField委托并输入

- (void)textFieldDidBeginEditing:(UITextField *)textField {
是吗

CGSize result = [[UIScreen mainScreen] bounds].size;

        if(result.height == 480){

        ({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -196; [self.view setFrame:frame]; [UIView commitAnimations];});
        }

        if(result.height == 568){

            ({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -196; [self.view setFrame:frame]; [UIView commitAnimations];});
        }

        if(result.height == 667){

            ({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -238; [self.view setFrame:frame]; [UIView commitAnimations];});
        }

        if(result.height == 736){

            ({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -251; [self.view setFrame:frame]; [UIView commitAnimations];});
        }
而且

- (void)textFieldDidEndEditing:(UITextField *)textField {
你只需要重新设置动画

({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = 0; [self.view setFrame:frame]; [UIView commitAnimations];});

您是否检查了contentSize属性

要使滚动视图可滚动,内容必须大于显示区域(通常为滚动视图的边界)

您可以通过显式地设置默认为CGSizeZero的属性来实现这一点


此外,设置属性以在弹出键盘时调整显示区域的大小(在这种情况下,您可以设置底部值等于键盘高度)

是否可以显示/发布代码?添加内容后是否设置了scrollview的contentSize?
({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = 0; [self.view setFrame:frame]; [UIView commitAnimations];});