HeathWang / HWPanModal

HWPanModal presents controller from bottom and drag to dismiss, high customize. iOS13 default modalPresentationStyle. 任意形式的底部弹框动画;头条、知乎、抖音弹出评论效果;地图浮层,iOS13 present默认模态效果。
MIT License
1.17k stars 198 forks source link

继承HWPanModalContentView的自定义View,底部添加 UIVisualEffectView 不起磨玻璃作用 #46

Closed GrapeFruitJun closed 4 years ago

GrapeFruitJun commented 4 years ago

iOS 12.2 继承HWPanModalContentView的自定义View,底部添加 UIVisualEffectView 不起磨玻璃作用 直接变为透明度的图层

HeathWang commented 4 years ago

麻烦贴出代码我看一下,谢谢

GrapeFruitJun commented 4 years ago
@interface HWSimplePanModalView : HWPanModalContentView
@property (nonatomic, strong) UIVisualEffectView * backgroundBlurView;
@end
@implementation HWSimplePanModalView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        //1.第一种添加毛玻璃
        [self addSubview:self.backgroundBlurView];
        //2.直接赋值带有透明度的颜色
//        self.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.5];   
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    _backgroundBlurView.frame = self.bounds;
}
- (UIVisualEffectView *)backgroundBlurView{
    if (!_backgroundBlurView) {
        UIVisualEffect * effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
        _backgroundBlurView = [[UIVisualEffectView alloc] initWithEffect:effect];
    }
    return _backgroundBlurView;
}
// 没起作用
- (HWPanModalShadow)contentShadow {
    return PanModalShadowMake([UIColor yellowColor], 10, CGSizeMake(0, 2), 1);
}
// present it.
HWSimplePanModalView *simplePanModalView = [HWSimplePanModalView new];
[simplePanModalView presentInView:nil];
GrapeFruitJun commented 4 years ago

@HeathWang 楼主看到了吗?

HeathWang commented 4 years ago

@HeathWang 楼主看到了吗?

不好意思,最近比较忙,我看了给你答复

GrapeFruitJun commented 4 years ago

辛苦,麻烦您了

HeathWang commented 4 years ago
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor yellowColor];
    }
    return self;
}

- (BOOL)showDragIndicator {
    return NO;
}

- (PanModalHeight)longFormHeight {
    return PanModalHeightMake(PanModalHeightTypeMaxTopInset, 44);
}

- (CGFloat)topOffset {
    return [UIApplication sharedApplication].keyWindow.rootViewController.topLayoutGuide.length + 21;
}

// 以下2个协议方法配置模糊效果
- (CGFloat)backgroundBlurRadius {
    return 10;
}

- (UIColor *)backgroundBlurColor {
    return [UIColor lightGrayColor];
}

hi, 该框架提供了配置模糊效果的方法,见以上代码

HeathWang commented 4 years ago

contentShadow不起作用是个bug,暂时无用。 如果你想使用该效果,请使用ViewController

GrapeFruitJun commented 4 years ago
  1. 2个协议方法配置dismiss背景模糊效果在这个效果我实现,很不错
  2. 可能是我描述的有问题,我们的层级是下面这样的(还是上面的代码):
HeathWang commented 4 years ago

对,UIVisualEffectView失去磨砂效果我也复现了,后续我会排查修复

HeathWang commented 4 years ago

@GrapeFruitJun UIVisualEffectView加到HWPanModalContentView没有效果在现有的设计下无法解决,我在底层更新了配置,新增了一个方法可以配置系统默认的模糊效果。

/**
 * use this object to config background alpha or blur effect
 * @return background config object
 */
- (HWBackgroundConfig *)backgroundConfig;

请更新库版本到0.7.0

HeathWang commented 4 years ago

@GrapeFruitJun 如果没问题,我先关闭该issue了,谢谢

HeathWang commented 4 years ago

contentShadow不起作用是个bug,暂时无用。 如果你想使用该效果,请使用ViewController

@GrapeFruitJun

🚀 HWPanModal (0.7.1) successfully published 📅 April 24th, 04:34 🌎 https://cocoapods.org/pods/HWPanModal 👍 Tell your friends!

GrapeFruitJun commented 4 years ago

已推荐 @HeathWang 👍