gpt4 book ai didi

ios - 显示窗口级别的 View UIWindowLevelStatusBar 退出当前的第一响应者

转载 作者:行者123 更新时间:2023-11-29 12:24:27 25 4
gpt4 key购买 nike

我在尝试在应用程序内显示应用内横幅(状态栏上方)时遇到问题。问题是,当我在文本字段中输入文本时,如果横幅出现,它会移除键盘,然后一旦横幅消失(它在计时器上),键盘就会再次出现。有没有办法在状态栏上方有一个横幅 View ,同时如果键盘是第一响应者,键盘不会消失。

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

最佳答案

我找到了解决方案。创建自定义 UIWindow 并将 UIView 作为 subview 添加到其中。这为我解决了问题。还有一件事是您必须重写“hitTest:withEvent”方法,因为默认情况下所有触摸都将转到窗口。因此,对于自定义窗口不应该处理的点击,它必须进一步委托(delegate)它。

我创建了一个自定义的 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

在我的 Controller 文件中

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

然后将自定义 View 作为 subview 添加到自定义窗口。

 [self.notificationWindow addSubview: _topView];

关于ios - 显示窗口级别的 View UIWindowLevelStatusBar 退出当前的第一响应者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29663063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com