2016-12-12 8 views
0

UITextViewをアニメーション化して、そのUIToolbarを含む幅に展開しようとしています。 しかし、それは変わって、飛び回っています。UIToolbarの問題でUITextviewをアニメーション化する

enter image description here

誰も私が私のテキストボックスは、周りのジャンプ理由を理解するのに役立つことはできますか?

#define ANIMATION_DURATION 0.5 
#define ANIMATION_DELAY 0.03 
    @interface WebViewController() <UITextFieldDelegate>{ 
     CGRect URLBAR_DEFAULT; 
    } 

    -(void)viewDidLoad{ 
    self.txtURLBar = [[UITextField alloc] init]; 
     self.txtURLBar.bounds = CGRectMake(0, 0, 100, 30); 
     self.txtURLBar.delegate = self; 
     self.txtURLBar.backgroundColor = [UIColor lightGrayColor]; 
     self.txtURLBar.clearButtonMode = UITextFieldViewModeWhileEditing; 


     URLBAR_DEFAULT = self.txtURLBar.frame; //KEEP A REFRENCE TO THE ORIGINAL SIZE 
    } 


//START EDITING EXPAND TO FULL WIDTH 
    - (void)textFieldDidBeginEditing:(UITextField *)textField { 
     [UIView animateWithDuration:ANIMATION_DURATION delay:ANIMATION_DELAY options:UIViewAnimationOptionCurveLinear animations:^{ 
      [_txtURLBar setFrame:CGRectMake(3, URLBAR_DEFAULT.origin.y, self.view.frame.size.width - 10, URLBAR_DEFAULT.size.height)]; 
     } completion:^(BOOL finished) { 

     }]; 

    } 

//END EDITING SHRINK BACK TO SMALL SIZE 
    - (void)textFieldDidEndEditing:(UITextField *)textField { 
     [UIView animateWithDuration:ANIMATION_DURATION delay:ANIMATION_DELAY options:UIViewAnimationOptionCurveEaseOut animations:^{ 
      [_txtURLBar setFrame:CGRectMake(URLBAR_DEFAULT.origin.x, URLBAR_DEFAULT.origin.y, URLBAR_DEFAULT.size.width, URLBAR_DEFAULT.size.height)]; 
     } completion:^(BOOL finished) { 

     }]; 
    } 

答えて

0

問題がtextFieldDidBeginEditingに設定されているフレームが原因である可能性があり、textFieldDidEndEditingが異なっています。私はあなたと同じコードで小さなPOCを以下のようにしました。それは正常に動作しています。

@interface ViewController() 

@property (weak, nonatomic) IBOutlet UITextField *resizeableTextField; 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 


- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


//START EDITING EXPAND TO FULL WIDTH 
- (void)textFieldDidBeginEditing:(UITextField *)textField { 
    [UIView animateWithDuration:0.5 delay:0.03 options:UIViewAnimationOptionCurveLinear animations:^{ 

     self.resizeableTextField.frame = CGRectMake(CGRectGetMinX(self.resizeableTextField.frame), CGRectGetMinY(self.resizeableTextField.frame), self.resizeableTextField.frame.size.width + 40, CGRectGetHeight(self.resizeableTextField.frame)); 
    } completion:^(BOOL finished) { 

    }]; 

} 

//END EDITING SHRINK BACK TO SMALL SIZE 
- (void)textFieldDidEndEditing:(UITextField *)textField { 
    [UIView animateWithDuration:0.5 delay:0.03 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
     self.resizeableTextField.frame = CGRectMake(CGRectGetMinX(self.resizeableTextField.frame), CGRectGetMinY(self.resizeableTextField.frame), self.resizeableTextField.frame.size.width - 40, CGRectGetHeight(self.resizeableTextField.frame)); 
    } completion:^(BOOL finished) { 

    }]; 
} 

@end 
関連する問題