RoomPopView.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // RoomPopView.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/8/3.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "RoomPopView.h"
  9. @interface RoomPopView ()
  10. @property(nonatomic, strong) UIView *shadowView;
  11. @property(nonatomic, strong) UIImageView *bgImageView;
  12. @property(nonatomic, strong) UIVisualEffectView *effectView;
  13. @end
  14. @implementation RoomPopView
  15. - (instancetype)initWithFrame:(CGRect)frame{
  16. if (self = [super initWithFrame:frame]) {
  17. self.backgroundColor = [UIColor colorWithHexString:@"#2B2739"];
  18. }
  19. return self;
  20. }
  21. - (void)awakeFromNib{
  22. [super awakeFromNib];
  23. // [self insertSubview:self.bgImageView atIndex:0];
  24. // [self insertSubview:self.effectView atIndex:0];
  25. }
  26. - (void)show:(UIView *)superView{
  27. //从底部弹出。与hide后 frame一致
  28. self.top = superView.height;
  29. [superView addSubview:self.shadowView];
  30. [superView addSubview:self];
  31. __weak __typeof(self)weakSelf = self;
  32. [UIView animateWithDuration:0.25 animations:^{
  33. __strong __typeof(weakSelf)strongSelf = weakSelf;
  34. strongSelf.frame = CGRectMake(strongSelf.left, superView.height - strongSelf.height, strongSelf.width, strongSelf.height);
  35. }];
  36. }
  37. - (void)hide{
  38. __weak __typeof(self)weakSelf = self;
  39. [UIView animateWithDuration:0.25 animations:^{
  40. __strong __typeof(weakSelf)strongSelf = weakSelf;
  41. strongSelf.frame = CGRectMake(strongSelf.left, self.superview.height, strongSelf.width, strongSelf.height);
  42. } completion:^(BOOL finished) {
  43. __strong __typeof(weakSelf)strongSelf = weakSelf;
  44. [strongSelf.shadowView removeFromSuperview];
  45. [strongSelf removeFromSuperview];
  46. }];
  47. }
  48. - (UIView *)shadowView{
  49. if (!_shadowView) {
  50. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  51. _shadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.4];
  52. _shadowView.userInteractionEnabled = YES;
  53. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  54. [_shadowView addGestureRecognizer:tap];
  55. }
  56. return _shadowView;
  57. }
  58. - (UIImageView *)bgImageView{
  59. if (!_bgImageView) {
  60. _bgImageView = [[UIImageView alloc]initWithFrame:self.bounds];
  61. _bgImageView.image = [UIImage imageNamed:@"live_bckgrund"];
  62. }
  63. return _bgImageView;
  64. }
  65. - (UIVisualEffectView *)effectView{
  66. if (!_effectView) {
  67. _effectView = [[UIVisualEffectView alloc]initWithFrame:self.bounds];
  68. UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  69. _effectView.effect = blur;
  70. }
  71. return _effectView;
  72. }
  73. - (void)setVagueImgUrl:(NSString *)vagueImgUrl{
  74. _vagueImgUrl = vagueImgUrl;
  75. [self vagueBackGround];
  76. }
  77. - (void)vagueBackGround
  78. {
  79. if (!_vagueImgView) {
  80. _vagueImgView = [[UIImageView alloc] initWithFrame:self.bounds];
  81. if (_vagueImgUrl && ![_vagueImgUrl isEqualToString:@""])
  82. {
  83. [_vagueImgView sd_setImageWithURL:[NSURL URLWithString:_vagueImgUrl]];
  84. }
  85. else
  86. {
  87. [_vagueImgView setImage:[UIImage imageNamed:@"background"]];
  88. }
  89. [self addSubview:_vagueImgView];
  90. [self insertSubview:_vagueImgView atIndex:0];
  91. // [self.faceView bringSubviewToFront:_vagueImgView];
  92. self.backgroundColor = [UIColor clearColor];
  93. UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  94. UIVisualEffectView *effectview = [[UIVisualEffectView alloc]initWithEffect:beffect];
  95. effectview.frame = self.bounds;
  96. [_vagueImgView addSubview:effectview];
  97. } else {
  98. [_vagueImgView sd_setImageWithURL:[NSURL URLWithString:_vagueImgUrl]];
  99. }
  100. }
  101. @end