TalkView.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // TalkView.m
  3. // XMEye
  4. //
  5. // Created by Wangchaoqun on 15/7/4.
  6. // Copyright (c) 2015年 Megatron. All rights reserved.
  7. //
  8. #import "TalkView.h"
  9. #import "Header.h"
  10. @implementation TalkView
  11. - (instancetype)init
  12. {
  13. self = [super init];
  14. if (self) {
  15. self.backgroundColor = [UIColor whiteColor];
  16. self.talkButton = [UIButton buttonWithType:UIButtonTypeCustom];
  17. [self.talkButton setBackgroundImage:[UIImage imageNamed:TS("press_talk")] forState:UIControlStateNormal];
  18. [self.talkButton setBackgroundImage:[UIImage imageNamed:TS("press_talk_selected")] forState:UIControlStateHighlighted];
  19. [self.talkButton addTarget:self action:@selector(talkToOther:) forControlEvents:UIControlEventTouchDown];
  20. [self.talkButton addTarget:self action:@selector(cannelTalk:) forControlEvents:UIControlEventTouchUpInside];
  21. [self.talkButton addTarget:self action:@selector(cannelTalk:) forControlEvents:UIControlEventTouchUpOutside];
  22. [self addSubview:self.talkButton];
  23. self.cannelButton = [UIButton buttonWithType:UIButtonTypeCustom];
  24. [self.cannelButton setBackgroundImage:[UIImage imageNamed:@"icon_close"] forState:UIControlStateNormal];
  25. [self.cannelButton addTarget:self action:@selector(cannelTheView) forControlEvents:UIControlEventTouchUpInside];
  26. [self addSubview:self.cannelButton];
  27. }
  28. return self;
  29. }
  30. //显示视图
  31. - (void)showTheView
  32. {
  33. CGFloat width = CGRectGetWidth(self.frame) > CGRectGetHeight(self.frame) ?
  34. CGRectGetHeight(self.frame) - 10:
  35. CGRectGetWidth(self.frame) - 10;
  36. self.talkButton.frame = CGRectMake(0, 0, width, width);
  37. self.talkButton.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
  38. self.cannelButton.frame = CGRectMake(CGRectGetWidth(self.frame) - 50, 0, 50, 50);
  39. CGRect frame = self.frame;
  40. self.frame = CGRectOffset(frame, 0, frame.size.height);
  41. [UIView animateWithDuration:0.2 animations:^{
  42. self.frame = frame;
  43. self.cannelButton.transform = CGAffineTransformMakeRotation(M_PI_2);
  44. } completion:^(BOOL finished) {
  45. if ([self.delegate respondsToSelector:@selector(openTalkView)]) {
  46. [self.delegate openTalkView];
  47. }
  48. }];
  49. }
  50. //关闭视图
  51. - (void)cannelTheView
  52. {
  53. [UIView animateWithDuration:0.2 animations:^{
  54. self.frame = CGRectOffset(self.frame, 0, self.frame.size.height);
  55. } completion:^(BOOL finished) {
  56. [self removeFromSuperview];
  57. if ([self.delegate respondsToSelector:@selector(closeTalkView)]) {
  58. [self.delegate closeTalkView];
  59. }
  60. }];
  61. }
  62. //打开通话
  63. - (void)talkToOther:(id)sender
  64. {
  65. UIButton *button = (UIButton*)sender;
  66. button.highlighted = true;
  67. if ([self.delegate respondsToSelector:@selector(openTalk)]) {
  68. [self.delegate openTalk];
  69. }
  70. }
  71. //关闭通话
  72. - (void)cannelTalk:(id)sender
  73. {
  74. UIButton *button = (UIButton*)sender;
  75. button.highlighted = false;
  76. if ([self.delegate respondsToSelector:@selector(closeTalk)]) {
  77. [self.delegate closeTalk];
  78. }
  79. }
  80. @end