문제

In my xib i have set one text box ...when user edit in it i am moving that view little up...but when i return back it to its original postion it not come to its original postion it remain little up then original postion. Here is 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;
    }

here is textfield delegate methods.:

 - (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);
}

and here is screenshot.:

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)

you should add 30 points for textfield to get to correct position.

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

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

}

Edit:

try this in your

 - (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 !!!!!);
                     }];


     }

and move textfield down after edit

- (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 !!!!!);
                     }];


     }

다른 팁

Set the textfield frames in viewWillAppear instead of viewDidLoad method.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top