1

アプリケーション内でアプリ内バナー (ステータス バーの上) を表示しようとすると問題が発生します。問題は、テキストフィールドにテキストを入力しているときに、バナーが表示されるとキーボードが削除され、バナーが消えるとキーボードが再び表示されることです(タイマー)。ステータス バーの上にバナー ビューを表示すると同時に、キーボードがファーストレスポンダの場合にキーボードが消えないようにする方法はありますか。

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];
4

1 に答える 1

1

解決策を見つけました。カスタム UIWindow を作成し、UIView をサブビューとして追加します。それは私にとって問題を解決します。もう 1 つのことは、すべてのタッチがデフォルトでウィンドウに移動するため、'hitTest:withEvent' メソッドをオーバーライドする必要があることです。そのため、カスタム ウィンドウが処理することになっていないタップについては、さらに委任する必要があります。

カスタム UIWindow クラスを作成しました:

@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

マイコントローラーファイル内

- (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;

}

次に、カスタム ビューをサブビューとしてカスタム ウィンドウに追加します。

 [self.notificationWindow addSubview: _topView];
于 2015-04-17T22:14:14.540 に答える