iPhone 键盘快速点击“下一步”按钮

发布于 2024-12-26 14:10:55 字数 2105 浏览 1 评论 0原文

在我的应用程序中,如果快速点击“下一步”按钮(返回键),则会出现问题。有什么办法可以阻止用户这样做吗?我自己也想不出解决办法。

我位于包含许多页面的 UIScrollView 中,并且在某个页面上有一个键盘弹出窗口,以便用户可以在 UITextField 中输入内容。点击下一页按钮会提示滚动视图滑动到下一页。但是,如果用户点击按钮过多,则会导致滚动视图跳跃。

下面的代码是当点击返回键时,关键部分是它调用 [self setPage:6];

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //Enter your first and last name
    if (textField == firstnameField1) 
    {
        //Put the text into a string to be saved
        firstName1 = firstnameField1.text;
        //Send user to next field (your surname)
        [surnameField1 becomeFirstResponder];
    }
    else if (textField == surnameField1)
    {
        //Put text into a string to be saved
        surname1 = surnameField1.text;
        //Move to the next stage, enter partners name
        if (pageController.currentPage == 4) {
            [self setPage:5];
        }
        else if (pageController.currentPage == 3)
        {
            [self setPage:5];
        }

        currentStage = stage6;
    }

    //Enter your partners first and last name
    if (textField == firstnameField2) 
    {
        //Put the text into a string to be saved
        firstName2 = firstnameField2.text;
        //Send user to next field (your partners surname)
        [surnameField2 becomeFirstResponder];
    }
    else if (textField == surnameField2)
    {
        //Put text into a string to be saved
        surname2 = surnameField2.text;
        //Move to the next stage, enter partners name
        if (pageController.currentPage == 5) {
            [self setPage:6];
        }
        else if (pageController.currentPage == 4)
        {
            [self setPage:6];
        }

        currentStage = stage7;
    }

    return YES;
}

该方法 setPage 如下:

-(void)setPage:(int)destinationPage
{
    //Scroll to appropriate page in scroll view
    CGRect frame = scrollViewController.frame;
    frame.origin.x = frame.size.width * destinationPage;
    frame.origin.y = 0;
    [scrollViewController scrollRectToVisible:frame animated:YES];
}

谢谢。

In my app, it causes problems if the 'Next' button (return key) is tapped rapidly. Is there a way I can stop the user from doing this? I can't think of a solution myself.

I am in a UIScrollView with many pages and on a certain page I have a keyboard popup so the user can type into a UITextField. Tapping the next button prompts the scroll view to slide to the next page. However, if the the user taps the button too much it causes the scroll view to jump about.

The code below is when the return key is tapped, the key part is it calls [self setPage:6];

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //Enter your first and last name
    if (textField == firstnameField1) 
    {
        //Put the text into a string to be saved
        firstName1 = firstnameField1.text;
        //Send user to next field (your surname)
        [surnameField1 becomeFirstResponder];
    }
    else if (textField == surnameField1)
    {
        //Put text into a string to be saved
        surname1 = surnameField1.text;
        //Move to the next stage, enter partners name
        if (pageController.currentPage == 4) {
            [self setPage:5];
        }
        else if (pageController.currentPage == 3)
        {
            [self setPage:5];
        }

        currentStage = stage6;
    }

    //Enter your partners first and last name
    if (textField == firstnameField2) 
    {
        //Put the text into a string to be saved
        firstName2 = firstnameField2.text;
        //Send user to next field (your partners surname)
        [surnameField2 becomeFirstResponder];
    }
    else if (textField == surnameField2)
    {
        //Put text into a string to be saved
        surname2 = surnameField2.text;
        //Move to the next stage, enter partners name
        if (pageController.currentPage == 5) {
            [self setPage:6];
        }
        else if (pageController.currentPage == 4)
        {
            [self setPage:6];
        }

        currentStage = stage7;
    }

    return YES;
}

That method setPage is below:

-(void)setPage:(int)destinationPage
{
    //Scroll to appropriate page in scroll view
    CGRect frame = scrollViewController.frame;
    frame.origin.x = frame.size.width * destinationPage;
    frame.origin.y = 0;
    [scrollViewController scrollRectToVisible:frame animated:YES];
}

Thanks.

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

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

发布评论

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

评论(1

赤濁 2025-01-02 14:10:55

从您的代码来看,您似乎正在超载“返回”按钮。您是否考虑过实现带有“下一个”/“上一个”按钮的工具栏< /a> 以便用户在意外点击时可以轻松返回到跳过的字段?

From your code, it looks like you're overloading the Return button. Have you considered implementing a toolbar with Next/Previous buttons so that the user can easily return to a skipped field if they accidentally overtap?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文