@@ -120,6 +120,7 @@ - (void)viewDidLoad {
120120 selector: @selector (keyboardWillHide: )
121121 name: UIKeyboardWillHideNotification
122122 object: nil ];
123+ NSLog (@" 注册键盘通知 updateFlutterContainerHeight" );
123124}
124125
125126- (void )updateFlutterContainerHeight : (CGFloat)height {
@@ -129,6 +130,7 @@ - (void)updateFlutterContainerHeight:(CGFloat)height {
129130 NSLog (@" start updateFlutterContainerHeight frame.origin.y:%f , frame.size.height:%f " , frame.origin .y , frame.size .height );
130131 CGFloat spaceY = height - frame.size .height ;
131132 frame.origin .y -= spaceY;
133+ _flutterContainerViewOriginY = frame.origin .y ;
132134 frame.size .height += spaceY;
133135 NSLog (@" end updateFlutterContainerHeight frame.origin.y:%f , frame.size.height:%f " , frame.origin .y , frame.size .height );
134136 [self .flutterContainer.view setFrame: frame];
@@ -157,15 +159,15 @@ - (void)didMoveToParentViewController:(UIViewController *)parent {
157159 [super didMoveToParentViewController: parent];
158160}
159161
160- /*
161- #pragma mark - Navigation
162-
163- // In a storyboard-based application, you will often want to do a little preparation before navigation
164- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
165- // Get the new view controller using [segue destinationViewController].
166- // Pass the selected object to the new view controller.
162+ - (void )showLog : (NSString *)log {
163+ // 格式化当前时间
164+ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc ] init ];
165+ [dateFormatter setDateFormat: @" yyyy-MM-dd HH:mm:ss.SSS" ];
166+ NSString *currentTimeString = [dateFormatter stringFromDate: [NSDate date ]];
167+
168+ // 打印时间戳和执行时间
169+ NSLog (@" [%@ ] %@ " , currentTimeString, log);
167170}
168- */
169171
170172- (void )dealloc {
171173 NSLog (@" dealloc native controller%p " , self.flutterContainer );
@@ -177,22 +179,21 @@ - (void)keyboardWillShow:(NSNotification *)notification {
177179 NSDictionary *info = [notification userInfo ];
178180 CGSize keyboardSize = [[info objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue ].size ;
179181 _keyboardHeight = keyboardSize.height ;
180-
182+
181183 CGRect frame = self.flutterContainer .view .frame ;
182- frame.origin .y -= _keyboardHeight;
184+ [self showLog: [NSString stringWithFormat: @" keyboardWillShow start updateFlutterContainerHeight frame.origin.y:%f , frame.size.height:%f " , frame.origin.y, frame.size.height]];
185+ frame.origin .y = _flutterContainerViewOriginY - _keyboardHeight;
183186 [self .flutterContainer.view setFrame: frame];
184-
185- // NSLog(@"Keyboard will show. Height: %f", keyboardHeight);
186- // 在这里可以对键盘弹起进行处理,比如调整界面布局
187+ [self showLog: [NSString stringWithFormat: @" keyboardWillShow end updateFlutterContainerHeight frame.origin.y:%f , frame.size.height:%f " , frame.origin.y, frame.size.height]];
187188}
188189
189190- (void )keyboardWillHide : (NSNotification *)notification {
190191 CGRect frame = self.flutterContainer .view .frame ;
192+ [self showLog: [NSString stringWithFormat: @" keyboardWillHide start updateFlutterContainerHeight frame.origin.y:%f , frame.size.height:%f " , frame.origin.y, frame.size.height]];
191193 frame.origin .y += _keyboardHeight;
194+ _flutterContainerViewOriginY = frame.origin .y ;
192195 [self .flutterContainer.view setFrame: frame];
193-
194- // NSLog(@"Keyboard will hide.");
195- // 在这里可以对键盘隐藏进行处理
196+ [self showLog: [NSString stringWithFormat: @" keyboardWillHide end updateFlutterContainerHeight frame.origin.y:%f , frame.size.height:%f " , frame.origin.y, frame.size.height]];
196197}
197198
198199@end
0 commit comments