1

I am having an issue where i am trying to show an in-app banner (above the status bar) within the application. The problem is that when i am in the middle to typing an text in the textfield, and if the banner shows up, it removes the keyboard, and then the keyboard show up again once the banner has been disappeared(it is on timer). Is there a way to have a banner view above status bar, and at the same time not have the keyboard disappear if the keyboard is the first responder.

InAppNotificationView* _sharedPushView = nil;
NSArray              * nibArr          = [[NSBundle mainBundle] loadNibNamed: @"InAppNotificationView" owner: self options: nil];
for (id currentObject in nibArr)
{
    if ([currentObject isKindOfClass: [InAppNotificationView class]])
    {
        _sharedPushView = (InAppNotificationView*) currentObject;
        break;
    }
}
_sharedPushView.delegate = self;

[self.displayedPushViews addObject: _sharedPushView];
                   _topView.window.windowLevel = UIWindowLevelStatusBar;
                   [UIView animateWithDuration: 0.25
                                    animations: ^
                                    {
                                        CGPoint centerPoint  = _sharedPushView.center;
                                        centerPoint.y       += _sharedPushView.frame.size.height;
                                        _sharedPushView.center      = centerPoint;
                                    }
                                    completion: nil];

                   [self.closeTimer invalidate];
                   self.closeTimer = nil;
                   self.closeTimer = [NSTimer scheduledTimerWithTimeInterval: 3.0f
                                                                      target: self
                                                                    selector: @selector(close)
                                                                    userInfo: nil
                                                                     repeats: NO];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
jerry
  • 274
  • 2
  • 19

1 Answers1

1

I found the solution. Create a custom UIWindow and add the UIView as a subview to it. That solves the problem for me. One more thing is that you'll have to override 'hitTest:withEvent' method as all the touches will go to the window by default. So for the taps that the custom window is not supposed to process, it will have to delegate it further.

I created a custom UIWindow class :

@interface InAppNotificationWindow : UIWindow
@property (assign, nonatomic) CGFloat notificationHeight;
@end
@implementation InAppNotificationWindow

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
      if (point.y > 0 && point.y < self.notificationHeight)
      {
          return [super hitTest: point withEvent: event];
      }
     return nil;
}
@end

In My Controller file

- (InAppNotificationWindow* ) notificationWindow
{
     if (_notificationWindow == nil)
     {
            _notificationWindow = [[InAppNotificationWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
            _notificationWindow.backgroundColor        = [UIColor clearColor];
           _notificationWindow.userInteractionEnabled = YES;
           _notificationWindow.hidden                 = NO;
          _notificationWindow.autoresizingMask       = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            _notificationWindow.windowLevel            = UIWindowLevelStatusBar;
     }

return _notificationWindow;

}

Then add the custom view as a subview to the custom window.

 [self.notificationWindow addSubview: _topView];
jerry
  • 274
  • 2
  • 19