UIScrollView和UITextField滚动和方向问题

发布于 2024-11-28 17:32:49 字数 158 浏览 2 评论 0原文

当键盘出现在文本字段上时,我遇到滚动问题,单击

我已尝试使用大量源代码,但它们不支持 iPad 的所有方向。

此外,当视图在 popoverview 中打开时,它也会产生问题。

可以做什么? 我想要动态解决方案而不是静态路径,提前谢谢大家 请帮助和建议。

I am facing problem in scrolling when keyboard appears on textfield click

I have tried using lots of source code but they not support all the orientation of iPad.

Also when view open in popoverview then it creates problem.

What could be done?
i want dynamic solution not static paches , thank you all in advance
Please Help and Suggest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-12-05 17:32:49

这里是滚动UITextfield的动态解决方案当显示键盘时。

基本代码:

    -(void)textFieldDidBeginEditing:(UITextField *)textField 
    {
        [self scrollViewToCenterOfScreen:textField];
    }

    - (void)textViewDidBeginEditing:(UITextView *)textView 
    {  
        [self scrollViewToCenterOfScreen:textView];  
    }  

    - (void)scrollViewToCenterOfScreen:(UIView *)theView 
    {  
        CGFloat viewCenterY = theView.center.y;  
        CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];    
        CGFloat availableHeight = applicationFrame.size.height - keyboardBounds.size.height;    // Remove area covered by keyboard    
        CGFloat y = viewCenterY - availableHeight / 2.0;  
        if (y < 0) {  
            y = 0;  
        }  
        scrollView.contentSize = CGSizeMake(applicationFrame.size.width, applicationFrame.size.height + keyboardBounds.size.height);  
        [scrollView setContentOffset:CGPointMake(0, y) animated:YES];  
    }

Here is the dynamic solution to scroll UITextfield while keyboard is being displayed.

Basic Code:

    -(void)textFieldDidBeginEditing:(UITextField *)textField 
    {
        [self scrollViewToCenterOfScreen:textField];
    }

    - (void)textViewDidBeginEditing:(UITextView *)textView 
    {  
        [self scrollViewToCenterOfScreen:textView];  
    }  

    - (void)scrollViewToCenterOfScreen:(UIView *)theView 
    {  
        CGFloat viewCenterY = theView.center.y;  
        CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];    
        CGFloat availableHeight = applicationFrame.size.height - keyboardBounds.size.height;    // Remove area covered by keyboard    
        CGFloat y = viewCenterY - availableHeight / 2.0;  
        if (y < 0) {  
            y = 0;  
        }  
        scrollView.contentSize = CGSizeMake(applicationFrame.size.width, applicationFrame.size.height + keyboardBounds.size.height);  
        [scrollView setContentOffset:CGPointMake(0, y) animated:YES];  
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文