iOS popover 如何去除阴影

iOS popover how to remove the shade

每当我们显示弹出窗口时,相邻区域都会显示不同类型的灰色,并且活动标签栏图标的颜色会从蓝色变为灰色,直到出现弹出窗口。

当弹出框被关闭时,灰色阴影被移除

我想在弹出窗口可见时移除颜色

我用谷歌搜索了,但无论如何我都找不到这似乎是默认行为。

感谢任何帮助我解决问题的帮助

谢谢

创建您自己的自定义弹出视图并将其作为子视图添加到您的主视图之上,而不是 Apple 提供的默认视图。

为此,您可以创建自己的 UIPopoverBackgroundView 自定义弹出窗口背景。 您可以找到以下用于创建自定义 CustomPopoverBgView 的代码。

CustomPopoverBgView.h

#import <UIKit/UIKit.h>
    @interface CustomPopoverBgView : UIPopoverBackgroundView
{
    UIImageView *_borderImageView;
    UIImageView *_arrowView;
    CGFloat _arrowOffset;
    UIPopoverArrowDirection _arrowDirection;
}
@end

CustomPopoverBgView.m

#import "CustomPopoverBgView.h"
#define CONTENT_INSET 10.0
#define CAP_INSET 25.0
#define ARROW_BASE 25.0
#define ARROW_HEIGHT 25.0
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.layer.shadowColor = [[UIColor clearColor] CGColor];
        _borderImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"popover-bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(CAP_INSET,CAP_INSET,CAP_INSET,CAP_INSET)]];

        _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];

        [self addSubview:_borderImageView];
        [self addSubview:_arrowView];
    }
    return self;
}
+(UIEdgeInsets)contentViewInsets{
    return UIEdgeInsetsMake(CONTENT_INSET, CONTENT_INSET, CONTENT_INSET, CONTENT_INSET);
}

+(CGFloat)arrowHeight{
    return ARROW_HEIGHT;
}

+(CGFloat)arrowBase{
    return ARROW_BASE;
}
- (CGFloat) arrowOffset {
    return _arrowOffset;
}

- (void) setArrowOffset:(CGFloat)arrowOffset {
    _arrowOffset = arrowOffset;
}
- (void)setArrowDirection:(UIPopoverArrowDirection)arrowDirection {
    _arrowDirection = arrowDirection;
}
- (UIPopoverArrowDirection)arrowDirection {
    return _arrowDirection;
}
@end

UIPopoverController

中调用CustomPopoverBgView
 UIButton *btn = (UIButton *)sender;
 ViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"dddddd"];
 controller.view.backgroundColor = [UIColor redColor];
 UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:controller] ;

 popoverController.popoverBackgroundViewClass = [CustomPopoverBgView class];
[popoverController presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];

希望对您有所帮助。