Multitasking Animation Toolbar

So, after my long search through google and SO, I did not find a similar problem. Some came close, but not like mine.

The problem is at hand: In my application (based on WKWebView), if the keyboard is displayed, and I switch home twice and switch to another application that is displayed on the keyboard, the application keyboard is hidden. Not a mistake. Therefore, when I multitask again, in the snapshot that my application needs, the keyboard is gone, but the user toolbar above which I was above seemed to be in place without a keyboard. I click on my application and it animates and then returns to the bottom of the screen.

What I tried: I know about [self.view endEditing: YES], resigningFirstResponder and all keyboard closing methods. Tried placing and moving through viewWillDisappear, applicationWillResignActive and applicationDidEnterBackground. None of them will handle my toolbar issue.

This is how I animate the keyboard on the screen and beyond, while maintaining the visibility of the toolbar.

- (void)keyboardWillShow:(NSNotification*)notification { NSDictionary* info = [notification userInfo]; NSNumber *durationValue = info[UIKeyboardAnimationDurationUserInfoKey]; NSNumber *curveValue = info[UIKeyboardAnimationCurveUserInfoKey]; NSValue *endFrame = info[UIKeyboardFrameEndUserInfoKey]; [UIView animateWithDuration:durationValue.doubleValue delay:0 options:(curveValue.intValue << 16) animations:^{ self.toolBar.frame = CGRectMake(0, [endFrame CGRectValue].origin.y - self.toolBar.bounds.size.height+44, self.toolBar.bounds.size.width, self.toolBar.bounds.size.height); } completion:nil]; } - (void)keyboardWillHide:(NSNotification*)notification { NSDictionary* info = [notification userInfo]; NSNumber *durationValue = info[UIKeyboardAnimationDurationUserInfoKey]; NSNumber *curveValue = info[UIKeyboardAnimationCurveUserInfoKey]; NSValue *endFrame = info[UIKeyboardFrameEndUserInfoKey]; [UIView animateWithDuration:durationValue.doubleValue delay:0 options:(curveValue.intValue << 16) animations:^{ self.toolBar.frame = CGRectMake(0, [endFrame CGRectValue].origin.y - self.toolBar.bounds.size.height, self.toolBar.bounds.size.width, self.toolBar.bounds.size.height); } completion:nil]; } 

Does anyone have a clue or thought?

Again, my application is based on WKWebView, so directly accessing or accessing text views, trying to focus on web browsing is pointless.

If anyone needs another code, just let me know. Any help would be greatly appreciated. Thanks.

UPDATED 1/20/18

So, here is the requested code related to where and how my toolbar is initialized and loaded.

h

 UIToolbar *toolBar; @property (nonatomic, strong) UIToolbar *toolBar; 

t

 @synthesize toolBar; - (void)viewDidLoad { //Toolbar setup CGRect toolFrame, remain; CGRectDivide(self.view.bounds, &toolFrame, &remain, 48, CGRectMaxYEdge); self.toolBar = [[UIToolbar alloc] initWithFrame:toolFrame]; [self.toolBar setBarStyle:UIBarStyleBlackTranslucent]; [self.toolBar setClipsToBounds:YES]; [self.toolBar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin]; [self.view addSubview:self.toolBar]; } 

Something about this, in addition, some code causes an update, when I switch the buttons, nothing is tied to this toolbar.

This does not cause a call unless I touch the switch or update it when the user changes the background, Dealt with NSUserDefaults in a different view.

 -(void)viewWillLayoutSubviews{ [self.currentScrollView layoutIfNeeded]; [self.toolBar layoutIfNeeded]; [self.view layoutSubviews]; } 
+5
source share
1 answer

So here is what works for me.

In my AppDelegate.m, I just add endEditing:

 - (void)applicationWillResignActive:(UIApplication *)application { [self.window endEditing:YES]; } 

Now in my keyboard the WillShow notification:

  - (void)keyboardWillShow:(NSNotification*)notification { /////New added method////// if([UIApplication sharedApplication].applicationState != UIApplicationStateActive){ return; } NSDictionary* info = [notification userInfo]; NSNumber *durationValue = info[UIKeyboardAnimationDurationUserInfoKey]; NSNumber *curveValue = info[UIKeyboardAnimationCurveUserInfoKey]; NSValue *endFrame = info[UIKeyboardFrameEndUserInfoKey]; [UIView animateWithDuration:durationValue.doubleValue delay:0 options:(curveValue.integerValue << 16) animations:^{ self.toolBar.frame = CGRectMake(0, [endFrame CGRectValue].origin.y - self.toolBar.bounds.size.height+44, self.toolBar.bounds.size.width, self.toolBar.bounds.size.height); } completion:nil]; } 

Everything was so simple. Just hiding the keyboard, as before, and check if the application is active.

Now, when I double-click on the house, the keyboard is hiding. If I switch to another application, such as Messages, draw a keyboard, double-tap it and return to my application, the keyboard never moved. The solution to my problem.

0
source

Source: https://habr.com/ru/post/1263995/


All Articles