大佬教程收集整理的这篇文章主要介绍了ios – 动画UITextField时的奇怪行为,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在第一个状态下,应用程序具有UITextField,相机UIButton和取消UIButton之后未显示的相机按钮,因为它已被定位在应用程序的限制范围之外.实际上我的应用程序有320的宽度和取消按钮来源是(350,7)
在第二状态,当用户触摸UITextField时,相机按钮alpha通道设置为0,取消按钮的原点设置为(247,7).
用户触摸键盘的返回按钮或取消按钮后,最终状态与第一状态相同.
在处理期间,UITextField宽度和x轴上的取消按钮原点是动画的.
我的代码是:
- (void)textFieldDidBeginEdiTing:(UITextField *)textField { barcodeSearchButton.userInteractionEnabled = NO; cancelButton.userInteractionEnabled = NO; CGFloat cancelButtonXOffset = CGRectGetMaxX(barcodeSearchButton.framE) - cancelButton.frame.size.width; CGFloat searchFieldWidth = searchField.frame.size.width - cancelButton.frame.size.width + barcodeSearchButton.frame.size.width; [UIView animateWithDuration:0.3 animations:^{ searchField.frame = CGRectMake(searchField.frame.origin.x,searchField.frame.origin.y,searchFieldWidth,searchField.frame.size.height); cancelButton.alpha = 1.0; cancelButton.frame = CGRectMake(cancelButtonXOffset,cancelButton.frame.origin.y,cancelButton.frame.size.width,cancelButton.frame.size.height); barcodeSearchButton.alpha = 0.0; } completion:^(BOOL finished) { barcodeSearchButton.userInteractionEnabled = NO; cancelButton.userInteractionEnabled = YES; }]; } - (void)textFieldDidEndEdiTing:(UITextField *)textField { barcodeSearchButton.userInteractionEnabled = NO; cancelButton.userInteractionEnabled = NO; [UIView animateWithDuration:0.3 animations:^{ searchField.frame = CGRectMake(searchField.frame.origin.x,searchFieldStartWidth,searchField.frame.size.height); cancelButton.alpha = 0.0; cancelButton.frame = CGRectMake(cancelButtonStartX,cancelButton.frame.size.height); barcodeSearchButton.alpha = 1.0; } completion:^(BOOL finished) { barcodeSearchButton.userInteractionEnabled = YES; cancelButton.userInteractionEnabled = NO; }]; }
当动画第一次执行到最终状态时,这意味着,用户触摸了UITextField,WROTE DOWN(这部分很重要)场上的一些文本,然后用户触摸键盘返回按钮就会出现问题.问题是,当UITextField的宽度也被动画化时,UITextField中的键入文本也会被动画化.
动画表现得像波纹管:
> UITextField延伸回其初始值.
>取消按钮返回其初始原点
>相机按钮设置为1.0
>键入的文本从UITextField的左上角飞过,它进入UITextfield到它不应该离开的位置.
问题是第4步不应该发生,问题是它只发生一次.如果再次启动该过程(触摸uitextfield,键入一些文本,触摸返回键),则步骤4不会发生.
我的第一次尝试是覆盖textFieldDidBeginEdiTing和textFieldDidEndEdiTing来创建动画.我不知道动画在textFieldShouldBeginEdiTing和textFieldShouldEndEdiTing中工作的原因,但在textFieldDidBeginEdiTing和textFieldDidEndEdiTing中没有.但它只是有效.
- (BOOL)textFieldShouldBeginEdiTing:(UITextField *)textField { CGFloat cancelButtonXOffset = CGRectGetMaxX(barcodeSearchButton.framE) - cancelButton.frame.size.width; CGFloat searchFieldWidth = searchField.frame.size.width - cancelButton.frame.size.width + barcodeSearchButton.frame.size.width; [UIView animateWithDuration:0.3 animations:^{ searchField.frame = CGRectMake(searchField.frame.origin.x,cancelButton.frame.size.height); barcodeSearchButton.alpha = 0.0; } completion:^(BOOL finished) { searchField.clearButtonMode = UITextFieldviewmodeAlways; }]; return YES; } - (BOOL)textFieldShouldEndEdiTing:(UITextField *)textField { [UIView animateWithDuration:0.3 animations:^{ searchField.frame = CGRectMake(searchField.frame.origin.x,searchField.frame.size.height); cancelButton.alpha = 0.0; cancelButton.frame = CGRectMake(cancelButtonStartX,cancelButton.frame.size.height); barcodeSearchButton.alpha = 1.0; } completion:^(BOOL finished) { searchField.clearButtonMode = UITextFieldviewmodeNever; }]; return YES; }
以上是大佬教程为你收集整理的ios – 动画UITextField时的奇怪行为全部内容,希望文章能够帮你解决ios – 动画UITextField时的奇怪行为所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。