OtherRoomBitGiftView.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // OtherRoomBitGiftView.m
  3. // FanweApp
  4. //
  5. // Created by xfg on 2017/7/12.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "OtherRoomBitGiftView.h"
  9. static float const kAnimateTimes = 12; // 动画时间
  10. @implementation OtherRoomBitGiftView
  11. - (id)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self)
  15. {
  16. self.backgroundColor = kClearColor;
  17. self.largeGiftBtn = [[MenuButton alloc] initWithFrame:CGRectMake(frame.size.width, 0, 0, frame.size.height)];
  18. [self.largeGiftBtn.titleLabel setFont:kAppMiddleTextFont];
  19. self.largeGiftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  20. self.largeGiftBtn.titleEdgeInsets = UIEdgeInsetsMake(10, 50, 0, 0);
  21. self.largeGiftBtn.userInteractionEnabled = NO;
  22. [self addSubview:self.largeGiftBtn];
  23. }
  24. return self;
  25. }
  26. - (void)judgeGiftViewWith:(NSString *)str finishBlock:(FWVoidBlock)finishBlock
  27. {
  28. CGSize strSize = [str sizeWithAttributes:@{NSFontAttributeName : self.largeGiftBtn.titleLabel.font}];
  29. self.largeGiftBtn.frame = CGRectMake(CGRectGetMinX(self.largeGiftBtn.frame), CGRectGetMinY(self.largeGiftBtn.frame) + kRealValue(5), strSize.width + 70, CGRectGetHeight(self.largeGiftBtn.frame));
  30. [self.largeGiftBtn setBackgroundImage:[BGUtils resizableImage:@"lr_bg_fly_gift"] forState:UIControlStateNormal];
  31. [self.largeGiftBtn setTitle:str forState:UIControlStateNormal];
  32. [UIView animateWithDuration:kAnimateTimes delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
  33. self.largeGiftBtn.frame = CGRectMake(- CGRectGetWidth(self.largeGiftBtn.frame), CGRectGetMinY(self.largeGiftBtn.frame), CGRectGetWidth(self.largeGiftBtn.frame), CGRectGetHeight(self.largeGiftBtn.frame));
  34. } completion:^(BOOL finished) {
  35. self.hidden = YES;
  36. self.largeGiftBtn.frame = CGRectMake(self.frame.size.width, CGRectGetMinY(self.largeGiftBtn.frame), strSize.width + 52, CGRectGetHeight(self.largeGiftBtn.frame));
  37. if (finishBlock)
  38. {
  39. finishBlock();
  40. }
  41. }];
  42. }
  43. @end