EaseBubbleView+Video.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /************************************************************
  2. * * Hyphenate CONFIDENTIAL
  3. * __________________
  4. * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
  5. *
  6. * NOTICE: All information contained herein is, and remains
  7. * the property of Hyphenate Inc.
  8. * Dissemination of this information or reproduction of this material
  9. * is strictly forbidden unless prior written permission is obtained
  10. * from Hyphenate Inc.
  11. */
  12. #import "EaseBubbleView+Video.h"
  13. @implementation EaseBubbleView (Video)
  14. #pragma mark - private
  15. - (void)_setupVideoBubbleMarginConstraints
  16. {
  17. NSLayoutConstraint *marginTopConstraint = [NSLayoutConstraint constraintWithItem:self.videoImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:self.margin.top];
  18. NSLayoutConstraint *marginBottomConstraint = [NSLayoutConstraint constraintWithItem:self.videoImageView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-self.margin.bottom];
  19. NSLayoutConstraint *marginLeftConstraint = [NSLayoutConstraint constraintWithItem:self.videoImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-self.margin.right];
  20. NSLayoutConstraint *marginRightConstraint = [NSLayoutConstraint constraintWithItem:self.videoImageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.backgroundImageView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:self.margin.left];
  21. [self.marginConstraints removeAllObjects];
  22. [self.marginConstraints addObject:marginTopConstraint];
  23. [self.marginConstraints addObject:marginBottomConstraint];
  24. [self.marginConstraints addObject:marginLeftConstraint];
  25. [self.marginConstraints addObject:marginRightConstraint];
  26. [self addConstraints:self.marginConstraints];
  27. }
  28. - (void)_setupVideoBubbleConstraints
  29. {
  30. [self _setupVideoBubbleMarginConstraints];
  31. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.videoTagView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.videoImageView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
  32. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.videoTagView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.videoImageView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
  33. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.videoTagView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.videoImageView attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0]];
  34. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.videoTagView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.videoTagView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0]];
  35. }
  36. #pragma mark - public
  37. - (void)setupVideoBubbleView
  38. {
  39. self.videoImageView = [[UIImageView alloc] init];
  40. self.videoImageView.translatesAutoresizingMaskIntoConstraints = NO;
  41. self.videoImageView.backgroundColor = [UIColor clearColor];
  42. [self.backgroundImageView addSubview:self.videoImageView];
  43. self.videoTagView = [[UIImageView alloc] init];
  44. self.videoTagView.translatesAutoresizingMaskIntoConstraints = NO;
  45. self.videoTagView.backgroundColor = [UIColor clearColor];
  46. [self.videoImageView addSubview:self.videoTagView];
  47. [self _setupVideoBubbleConstraints];
  48. }
  49. - (void)updateVideoMargin:(UIEdgeInsets)margin
  50. {
  51. if (_margin.top == margin.top && _margin.bottom == margin.bottom && _margin.left == margin.left && _margin.right == margin.right) {
  52. return;
  53. }
  54. _margin = margin;
  55. [self removeConstraints:self.marginConstraints];
  56. [self _setupVideoBubbleMarginConstraints];
  57. }
  58. @end