gpt4 book ai didi

ios - iPad-物镜-C-键盘-一切都从左向右移动,而不是向下移动

转载 作者:行者123 更新时间:2023-12-01 18:55:25 25 4
gpt4 key购买 nike

我希望这个问题有意义,我有一个登录屏幕,当我单击一个输入字段(“用户名”或“密码”)时,将出现一个键盘。但是当这种情况发生时,一切都会从左到右运动,所以我在左侧有一个很大的空白。我期望的是一切都将从向下移动。我真的希望这是有道理的。这是我的代码:

- (void)animateTextField:(UITextField *) textField up: (BOOL) up;
- (void)NavButtonPressed: (UIButton*)sender;

- (void)NavButtonPressed: (UIButton*)sender
{
if([sender isEqual:navBarNextButton])
{
[self.idTextField resignFirstResponder];
[self.passwordTextField becomeFirstResponder];
currentResponder = 1;
[self animateTextField:self.passwordTextField up:NO];
[self animateTextField:self.passwordTextField up:YES];
[navBarNextButton setEnabled:NO];
[navBarPrevButton setEnabled:YES];

}
else
{
[self.passwordTextField resignFirstResponder];
[self.idTextField becomeFirstResponder];
currentResponder = 0;
[self animateTextField:self.idTextField up:NO];
[self animateTextField:self.idTextField up:YES];
[navBarNextButton setEnabled:YES];
[navBarPrevButton setEnabled:NO];
}
}

- (void)animateTextField:(UITextField *) textField up: (BOOL) up
{
int movementDistance;
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
if([textField isEqual:self.idTextField])
{
[textfieldNavigatorView setFrame:CGRectMake(0.0f, (1024.0f/2.0f)-31.5f, 1024.0f, 45.0f)];
movementDistance = 110;
}
else
{
[textfieldNavigatorView setFrame:CGRectMake(0.0f, (1024.0f/2.0f)-26.5f, 1024.0f, 45.0f)];
movementDistance = 115;
}
}
else
{movementDistance = 0;}

const float movementDuration = 0.3f;
int movement=0;
if([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft)
movement = (up? -movementDistance : movementDistance);
if([self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
movement = (up? movementDistance : -movementDistance);

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

[UIView commitAnimations];
}

如果有人可以帮助,那将是惊人的。我的项目设备设置为仅横向权限。

最佳答案

我之前遇到过同样的问题,在iOS 7和8中,它的工作方式有所不同。因此,我实现了一种处理该问题的方法:

- (void)keyboardHideShow:(UIView *)view shiftBy:(float)shiftAmount forState:(BOOL)state
{
float keyBoardOffset = shiftAmount;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGRect rect = [[[UIApplication sharedApplication] keyWindow] bounds];
if (state)
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8)
{
if (orientation == UIInterfaceOrientationLandscapeLeft)
{
rect.origin.x -= keyBoardOffset;
}
else
{
rect.origin.x += keyBoardOffset;
}
}
else
{
rect.origin.y -= keyBoardOffset;
}
}
view.frame = rect;
[UIView commitAnimations];
}

您可以这样称呼它:
[self keyboardHideShow:textfieldNavigatorView shiftBy:31.5 forState:true];  // For up
[self keyboardHideShow:textfieldNavigatorView shiftBy:31.5 forState:false]; // For down

关于ios - iPad-物镜-C-键盘-一切都从左向右移动,而不是向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27611236/

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