gpt4 book ai didi

ios - 当键盘出现在 4s 、 5 和 5s 等小屏幕上时如何向上移动 View 但是当它进入 iphone 6 时 View 不应该向上移动

转载 作者:行者123 更新时间:2023-12-01 17:49:31 24 4
gpt4 key购买 nike

如何在 4s、5 和 5s 等小屏幕上出现键盘时向上移动 View ,但在 iphone 6 和 6S 内进入时 View 不应该向上移动。

我正在分享我的代码,这是我在我的应用程序中为所有屏幕完成的,但在我的条件 View 中,当它进入 6 秒或 6 秒时,它不应该向上移动。

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField:textField up:YES];
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField:textField up:NO];
}

-(void)animateTextField:(UITextField*)textField up:(BOOL)up
{
const int movementDistance = -60; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed

int movement = (up ? movementDistance : -movementDistance);

[UIView beginAnimations: @"animateTextField" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}

最佳答案

我建议你使用 IQKeyboardManager它将以更少的努力为您管理一切

关于ios - 当键盘出现在 4s 、 5 和 5s 等小屏幕上时如何向上移动 View 但是当它进入 iphone 6 时 View 不应该向上移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35476165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com