Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status bar disappears in iOS 11 #1122

Closed
jaymathew opened this issue Nov 9, 2017 · 22 comments
Closed

Status bar disappears in iOS 11 #1122

jaymathew opened this issue Nov 9, 2017 · 22 comments
Milestone

Comments

@jaymathew
Copy link

jaymathew commented Nov 9, 2017

Hello,

The following issue only happens on iOS 11 and on both simulator and real devices.

When the keyboard comes up everything is fine, but when I tap done the keyboard lowers and I have no status bar left and all components on that view are moved up. The next time the keyboard rises and lowers the status bar is back. The missing status bar happens ever other raise and lower of the keyboard. Below are some screenshots that help relay the issue, the black marks are my vertical constraints that connect the bottom and top of the view. The TextView at the bottom doesn't have a height constraint so on smaller devices it shrinks

demo 2
demo1

@hackiftekhar
Copy link
Owner

iOS11 introduce lots of new features which affects library very badly.

@jaymathew
Copy link
Author

Is a fix on the way?

@GamexStudio
Copy link

I am facing the same issue. Is there any workaround for this?

@hackiftekhar
Copy link
Owner

Currently no workaround. Can someone upload sample code to reproduce this issue?

@ugomarinelli
Copy link

ugomarinelli commented Jan 31, 2018

Hi guys, my workaround was :

In IQKeyboardManager.swift, inside the keyboardDidHide method, add the following :

let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView

if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
    statusBar.backgroundColor = UIColor.white
}

in the end, your keyboardDidHide look like this :

@objc internal func keyboardDidHide(_ notification:Notification) {

    let startTime = CACurrentMediaTime()
    showLog("****** \(#function) started ******")
    
    _topViewBeginRect = CGRect.zero
    
    let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView

    if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
        statusBar.backgroundColor = UIColor.white
    }
    
#if swift(>=3.2)
    if #available(iOS 11, *) {
        _initialAdditionalSafeAreaInsets = .zero;
    }
#endif
    
    _kbSize = CGSize.zero

    let elapsedTime = CACurrentMediaTime() - startTime
    showLog("****** \(#function) ended: \(elapsedTime) seconds ******")
}

I know it is maybe not the best since I harcoded the background to be white but that made the trick for me . One solution for you could be to store the background color of the status bar in a variable before the keyboard appears and reattributting this color in the KeyboardDidHide .

@seon1-k
Copy link

seon1-k commented Feb 11, 2018

i have same issue...

@ghost
Copy link

ghost commented Feb 18, 2018

Here is the solution:
#1190
@seonift

@hackiftekhar hackiftekhar added this to the v6.0.0 milestone Mar 12, 2018
@hackiftekhar
Copy link
Owner

It's fixed with new solution, changes are in master branch now. Please check and let me know if it doesn't work for you.

@nCr78
Copy link

nCr78 commented Apr 14, 2018

This still happens for some reason even when having the deprecated "canAdjustAdditionalSafeAreaInsets" boolean set to true. (Using v6.0.0 from cocoapods)

Disabling the manager stops it from happening so it can't possibly be my implementation..

@hackiftekhar
Copy link
Owner

@nCr78 can you please share a demo project using v6.0.0?

@hackiftekhar hackiftekhar reopened this Apr 14, 2018
@nCr78
Copy link

nCr78 commented Apr 15, 2018

@hackiftekhar Yes give me some time to isolate my implementation and I'll upload a gist of a view controller

@hackiftekhar
Copy link
Owner

It would be better if you provide the demo project instead of code of a single view controller. It's better for me otherwise I'll have to do extra work to integrate your code to another demo project and all that.

@nCr78
Copy link

nCr78 commented Apr 15, 2018

Alright, will do it as a project! No problem :)

@nCr78
Copy link

nCr78 commented Apr 16, 2018

Upon trying to isolate and reproduce the issue onto a new project, I found out that it's caused by a combination of your project and another open source project. This complicates things because I don't know exactly which parts of each project are conflicting except from their custom tab bar controller.

On top of that, I could only reproduce it on a physical iPhone X (iOS 11+). I've tried the simulator and the status bar stays as it is. I ran it on a physical iPhone 7 (iOS 11+) and the issue isn't there either.

Here's the project in case you want to check it out. I might have to change my implementation as I don't see how this is fixable - my guess is safe areas and UIView extension conflicts.

keyboardtest.zip

img_0663

@hackiftekhar
Copy link
Owner

I started reviewing the demo project. However I don't have physical iPhoneX or iPhone8+ size device so I'm unable to reproduce this issue with this demo project and as you said it isn't reproducible with simulators. :(

@jacojoubert12
Copy link

I have the same problem. Tried upgrading to 6.0.4 but it still happens. Using iPhone6. Solutions for setting status bar color to white is not a solution, it just sets the status bar color to white ;-) Really need a fix for this.
Also, on one of my ViewControllers the arrows are the wrong way around. Any advice on how to fix that?

@hackiftekhar
Copy link
Owner

with the arrow fix, please make sure your textFields are in correct order in view hierarchy since it mostly happens with wrong view hierarchy.

@caijingsong
Copy link

i try to fix the bug.
have try in IOKeyboardManager.m:

  • (void)keyboardDidHide:(NSNotification*)aNotification
    {
    CFTimeInterval startTime = CACurrentMediaTime();
    [self showLog:[NSString stringWithFormat:@"****** %@ started ******",NSStringFromSelector(_cmd)]];

    _topViewBeginRect = CGRectZero;

    [[UIApplication sharedApplication].keyWindow setNeedsLayout];

    CFTimeInterval elapsedTime = CACurrentMediaTime() - startTime;
    [self showLog:[NSString stringWithFormat:@"****** %@ ended: %g seconds ******",NSStringFromSelector(_cmd),elapsedTime]];
    }

@codenia
Copy link

codenia commented Oct 1, 2018

I can also see this problem on the iPhone 6, 7 Plus and iPhone Xs Max. It does not happen the first time after closing the keyboard.
If I touch a text field, the keyboard pops up, then I close the keyboard and the status bar is still there. But if I touch the same text field for the second time, the keyboard pops up, then I close the keyboard and the status bar has disappeared. If I now touch the same text box again, the keyboard opens, I close the keyboard and the status bar is back.

It works in this pattern:

  1. status bar is OK
  2. status bar is NOK
  3. status bar is OK
  4. status bar is OK
  5. status bar is NOK
  6. status bar is OK
  7. status bar is OK
  8. status bar is NOK
    .....

So the behavior has a system. My keyboard settings are set like this:

screen

@codenia
Copy link

codenia commented Oct 1, 2018

I found the cause of the problem in my code. In the function viewDidLayoutSubviews I read and use the view.safeAreaInsets.top value. Sometimes if the keyboard show up the viewDidLayoutSubviews function is called. The value of view.safeAreaInsets.top is sometimes 0 instead of 20 or 44.

That's how I solved the problem:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    UIEdgeInsets safeAreaInsets;
    
    safeAreaInsets.left = 0;
    safeAreaInsets.right = 0;
    safeAreaInsets.top = [UIApplication sharedApplication].statusBarFrame.size.height;
    safeAreaInsets.bottom = 0;
    
    if (@available(iOS 11.0, *)) {
        safeAreaInsets.left = view.safeAreaInsets.left;
        safeAreaInsets.right = view.safeAreaInsets.right;
        if(self.view.safeAreaInsets.top != 0)
        {
            safeAreaInsets.top = self.view.safeAreaInsets.top;
        }
        
        if(self.view.safeAreaInsets.bottom != 0)
        {
            safeAreaInsets.bottom = self.view.safeAreaInsets.bottom;
        }
    }

   // some layout code
   ...
}

@nobird
Copy link

nobird commented Oct 25, 2018

try "IQKeyboardManager.shared().layoutIfNeededOnUpdate = true"
It works for me..

@Rajkiran93
Copy link

try "IQKeyboardManager.shared().layoutIfNeededOnUpdate = true"
It works for me..

Thanks works for me too...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests