gpt4 book ai didi

ios - View 未设置回原始位置

转载 作者:行者123 更新时间:2023-11-29 03:26:43 24 4
gpt4 key购买 nike

在我的 xib 中,我设置了一个文本框...当用户在其中编辑时,我将该 View 向上移动了一点...但是当我将其返回到其原始位置时,它没有回到其原始位置,它仍然很小到原来的位置。这是viewDidLoad

  - (void)viewDidLoad
{
[super viewDidLoad];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])self.edgesForExtendedLayout = UIRectEdgeNone;
search=FALSE;
UIButton *btnOther = [UIButton buttonWithType:UIButtonTypeSystem]; //UIButtonTypeCustom for image button
[btnOther setTitle:@"Save" forState:UIControlStateNormal];
btnOther.titleLabel.font = [UIFont fontWithName:GZFont size:12.0f];
// [btnSave setImage:[UIImage imageNamed:@"save.png"] forState:UIControlStateNormal];
[btnOther addTarget:self action:@selector(btnSaveAction:) forControlEvents:UIControlEventTouchUpInside];
[btnOther setFrame:CGRectMake(0, 0, 55, 29)];
dataArray=[[NSMutableArray alloc]init];
nameSearchArray=[[NSMutableArray alloc]init];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnOther];
txtCharityName.hidden=YES;
txtCharityMail.hidden=YES;
originalCenter=self.view.center;
}

这里是文本字段委托(delegate)方法。:

 - (void)textFieldDidBeginEditing:(UITextField *)textField {

if(textField==txtGratuity){
self.view.center=CGPointMake(originalCenter.x, originalCenter.y-30);
}
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
self.view.center=CGPointMake(originalCenter.x, originalCenter.y);
charityId=@"";
NSLog(@"charityID%@",charityId);
}

这是截图:

enter image description here enter image description here

最佳答案

as per this equation

frame.origin = center - (bounds.size / 2.0)

center = frame.origin + (bounds.size / 2.0)

您应该为文本字段添加 30 个点才能到达正确的位置。

- (void)textFieldDidEndEditing:(UITextField *)textField {

self.view.center=CGPointMake(originalCenter.x, originalCenter.y+30);
charityId=@"";
NSLog(@"charityID%@",charityId);

}

编辑:

在你的中尝试这个

 - (void)textFieldDidBeginEditing:(UITextField *)textField {

[UIView animateWithDuration:0.25
delay:0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{

CGRect frame;

// let's move our textField
frame = textField.frame;
frame.origin.y = frame.origin.y-30;
textField.frame=frame;

}
completion:^(BOOL finished){
if(finished) NSLog(@"Finished !!!!!);
}];


}

编辑后向下移动文本字段

- (void)textFieldDidEndEditing:(UITextField *)textField {

[UIView animateWithDuration:0.25
delay:0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{

CGRect frame;

// let's move our textField
frame = textField.frame;
frame.origin.y = frame.origin.y+30;
textField.frame=frame;

}
completion:^(BOOL finished){
if(finished) NSLog(@"Finished !!!!!);
}];


}

关于ios - View 未设置回原始位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20372089/

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