iPhone 键盘快速点击“下一步”按钮
Posted
技术标签:
【中文标题】iPhone 键盘快速点击“下一步”按钮【英文标题】:iPhone Keyboard Rapidly tapping 'Next' Button 【发布时间】:2012-01-10 21:03:35 【问题描述】:在我的应用程序中,如果快速点击“下一步”按钮(返回键)会导致问题。有没有办法阻止用户这样做?我自己想不出解决办法。
我在一个包含许多页面的 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];
谢谢。
【问题讨论】:
“它会导致问题”这可以是任何事情 - 更详细地描述您的问题! 添加了代码示例,抱歉之前缺少细节。 【参考方案1】:从您的代码看来,您正在重载“返回”按钮。您是否考虑过实现toolbar with Next/Previous buttons,以便用户在意外点击时可以轻松返回到跳过的字段?
【讨论】:
以上是关于iPhone 键盘快速点击“下一步”按钮的主要内容,如果未能解决你的问题,请参考以下文章