iOS popover如何去除阴影

Els*_*e P 5 objective-c uitabbarcontroller uipopovercontroller ios

每当我们显示popover时,neighbhouring区域显示不同种类的灰色,并且活动标签栏图标颜色从蓝色变为灰色,直到弹出为止.

当弹出窗口被解除时,灰色阴影被移除

当弹出窗口可见时,我想删除颜色

我用谷歌搜索但无论如何我似乎无法找到这种默认行为.

任何帮助,以帮助我解决问题,表示赞赏

谢谢

Mob*_*rix 4

为了实现这一点,您可以创建自己的自定义弹出框背景UIPopoverBackgroundView。您可以找到以下用于创建自定义 CustomPopoverBgView 的代码。

自定义PopoverBgView.h

#import <UIKit/UIKit.h>
    @interface CustomPopoverBgView : UIPopoverBackgroundView
{
    UIImageView *_borderImageView;
    UIImageView *_arrowView;
    CGFloat _arrowOffset;
    UIPopoverArrowDirection _arrowDirection;
}
@end
Run Code Online (Sandbox Code Playgroud)

自定义PopoverBgView.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
Run Code Online (Sandbox Code Playgroud)

呼入CustomPopoverBgViewUIPopoverController

 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];
Run Code Online (Sandbox Code Playgroud)

希望对你有帮助。