How to add UIView on keyboard - iOS

I am trying to display toasts in iOS. What I did was when some kind of notification came, only I took the view of the navigation manager and added a subview for my toast and displayed it.

    UIView *top_view = self.navigationController.view;
    [top_view showToast:string];

Everything works perfectly. However, my toast does not add on the keyboard (if the keyboard is in front). Any idea what might be the problem ... A little help can save my time ... Thanx ..

+2
source share
6 answers

You can display the toast by adding a subview to the main window.

UIWindow *toastDisplaywindow = [[[UIApplication sharedApplication] delegate] window];;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) 
{
   if (![[testWindow class] isEqual:[UIWindow class]]) 
    {
       self.toastDisplaywindow = testWindow;
       break;
    }
}
[toastDisplaywindow showToast:string];

, . , , . , -, .

, UIView ( ).

+8

:

UIWindow *window = [UIApplication sharedApplication].windows.lastObject;

.

+8

. , .

.

[[[UIApplication sharedApplication] windows] objectAtIndex:1]

, , .

+3

Another way is to add the UIWindow user interface and then set WindowLevel to +1 from the last window.

Something like that

NSArray *windows = [[UIApplication sharedApplication] windows];  
UIWindow *lastWindow = (UIWindow *)[windows lastObject];  
myWindow.windowLevel = lastWindow.windowLevel + 1;

Take a look at this topic https://forums.developer.apple.com/thread/16375

+1
source

Update for Swift3

UIApplication.shared.windows.last

+1
source

in iOS9, Aditya’s answer doesn’t work,

UIWindow *window = [UIApplication sharedApplication].windows.lastObject;

to work well

0
source

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


All Articles