HINSPDebugWindow.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // RMDebugWindow.m
  3. //
  4. //
  5. // Created by Christian Menschel on 16.08.14.
  6. // Copyright (c) 2014 tapwork. All rights reserved.
  7. //
  8. #import "HINSPDebugWindow.h"
  9. #import "NSObject+HeapInspector.h"
  10. @implementation HINSPDebugWindow
  11. {
  12. UIView *_contentView;
  13. UIView *_dragView;
  14. }
  15. - (instancetype)initWithFrame:(CGRect)frame
  16. {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. // Initialization code
  20. _contentView = [[UIView alloc] initWithFrame:CGRectZero];
  21. _contentView.backgroundColor = [UIColor colorWithWhite:0.94 alpha:0.94];
  22. [self addSubview:_contentView];
  23. _recordButton = [[HINSPRecordButton alloc] init];
  24. [_contentView addSubview:_recordButton];
  25. UIPanGestureRecognizer *pangesture = [[UIPanGestureRecognizer alloc]
  26. initWithTarget:self
  27. action:@selector(panGestureAction:)];
  28. _dragView = [[UIView alloc] init];
  29. _dragView.backgroundColor = [UIColor darkGrayColor];
  30. [_dragView addGestureRecognizer:pangesture];
  31. [_contentView addSubview:_dragView];
  32. _infoLabel = [[UILabel alloc] init];
  33. _infoLabel.font = [UIFont systemFontOfSize:10];
  34. _infoLabel.numberOfLines = 2;
  35. _infoLabel.backgroundColor = [UIColor clearColor];
  36. [_contentView addSubview:_infoLabel];
  37. _recordedButton = [UIButton buttonWithType:UIButtonTypeSystem];
  38. _recordButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  39. _recordedButton.hidden = YES;
  40. [_recordedButton setTitle:@"Recorded Heap" forState:UIControlStateNormal];
  41. [_contentView addSubview:_recordedButton];
  42. _activeButton = [UIButton buttonWithType:UIButtonTypeSystem];
  43. [_activeButton setTitle:@"Heap" forState:UIControlStateNormal];
  44. [_contentView addSubview:_activeButton];
  45. }
  46. return self;
  47. }
  48. static const CGFloat kDragViewWidth = 25.0f;
  49. static const CGFloat kRecordButtonLeftOffset = 10.0f;
  50. static const CGFloat kInfoLabelLeftOffset = 10.0f;
  51. static const CGFloat kInfoLabelHeight = 20.0f;
  52. static const CGFloat kActiveButtonWidth = 85.0f;
  53. static const CGFloat kButtonHeight = 20.0f;
  54. static const CGFloat kRecordedButtonWidth = 110.0f;
  55. static const CGFloat kContentViewHeight = 50.0f;
  56. static const CGFloat kContentViewY = 80.0f;
  57. - (void)layoutSubviews
  58. {
  59. [super layoutSubviews];
  60. CGRect contentViewRect = _contentView.frame;
  61. if (_contentView.frame.size.width == 0.0) {
  62. contentViewRect.origin.y = kContentViewY;
  63. }
  64. contentViewRect.size.width = [UIScreen mainScreen].bounds.size.width;
  65. contentViewRect.size.height = kContentViewHeight;
  66. _contentView.frame = contentViewRect;
  67. CGSize recordButtonSize = CGSizeMake(_contentView.bounds.size.height/1.5,
  68. _contentView.bounds.size.height/1.5);
  69. _recordButton.frame = CGRectMake(kRecordButtonLeftOffset,
  70. floorf((_contentView.bounds.size.height - recordButtonSize.height)/2),
  71. recordButtonSize.width,
  72. recordButtonSize.height);
  73. _dragView.frame = CGRectMake(_contentView.bounds.size.width - kDragViewWidth,
  74. 0.0f,
  75. kDragViewWidth,
  76. _contentView.bounds.size.height);
  77. CGFloat x = CGRectGetMaxX(_recordButton.frame) + kInfoLabelLeftOffset;
  78. CGFloat width = _contentView.bounds.size.width - _dragView.bounds.size.width - x;
  79. _infoLabel.frame = CGRectMake(x,
  80. _contentView.bounds.size.height - kInfoLabelHeight,
  81. width,
  82. kInfoLabelHeight);
  83. CGFloat buttonY = floorf((_contentView.bounds.size.height - kButtonHeight)/2);
  84. _recordedButton.frame = CGRectMake(_infoLabel.frame.origin.x - 2.0,
  85. buttonY,
  86. kRecordedButtonWidth,
  87. kButtonHeight);
  88. _activeButton.frame = CGRectMake(CGRectGetMaxX(_recordedButton.frame) + 20.0,
  89. buttonY,
  90. kActiveButtonWidth,
  91. kButtonHeight);
  92. }
  93. - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
  94. {
  95. BOOL allowTouch = NO;
  96. if (CGRectContainsPoint(_contentView.frame, point)) {
  97. allowTouch = YES;
  98. }
  99. if (self.rootViewController.presentedViewController) {
  100. allowTouch = YES;
  101. }
  102. return allowTouch;
  103. }
  104. - (void)panGestureAction:(UIPanGestureRecognizer *)panGesture
  105. {
  106. if (panGesture.state == UIGestureRecognizerStateChanged) {
  107. CGFloat selfHeight = _contentView.bounds.size.height;
  108. CGPoint newCenter = _contentView.center;
  109. // newCenter.x += [panGesture translationInView:self].x;
  110. newCenter.y += [panGesture translationInView:self].y;
  111. // Reset the translation of the recognizer.
  112. [panGesture setTranslation:CGPointZero inView:self];
  113. if (newCenter.y > selfHeight &&
  114. newCenter.y < [UIScreen mainScreen].bounds.size.height - selfHeight) {
  115. _contentView.center = newCenter;
  116. }
  117. }
  118. }
  119. @end