Skip to content

Commit

Permalink
支持内存悬浮球frame自定义
Browse files Browse the repository at this point in the history
  • Loading branch information
gsdios committed Feb 4, 2018
1 parent 18cb917 commit ef85c45
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
#import "OOMStatisticsInfoCenter.h"

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "QQLeakDataUploadCenter.h"
#import "QQLeakFileUploadCenter.h"
#import "QQLeakChecker.h"


/*! @brief 单次堆内存分配超过限制后的回调
*
* @param bytes 分配的内存值(bytes)
Expand Down Expand Up @@ -104,6 +106,9 @@ typedef void (^ChunkMallocBlock)(size_t bytes, NSString *stack);
/** 显示或者隐藏实时内存监控悬浮球。单击悬浮球可设置内存触顶阈值,长按悬浮球可调节悬浮球大小。 */
- (void)showMemoryIndicatorView:(BOOL)yn;

/** 自定义悬浮球frame */
- (void)setupMemoryIndicatorFrame:(CGRect)frame;

/** 监听实时内存回调block */
- (void)setStatisticsInfoBlock:(StatisticsInfoBlock)block;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ - (void)showMemoryIndicatorView:(BOOL)yn
[[OOMStatisticsInfoCenter getInstance] showMemoryIndicatorView:yn];
}

- (void)setupMemoryIndicatorFrame:(CGRect)frame
{
CGFloat wh = MAX(frame.size.width, frame.size.height);
CGRect newFrame = frame;
newFrame.size.width = wh;
newFrame.size.height = wh;
[[OOMStatisticsInfoCenter getInstance] setupMemoryIndicatorFrame:newFrame];
}

- (void)setupLeakChecker
{
QQLeakChecker *leakChecker = [QQLeakChecker getInstance];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ - (void)layoutSubviews
[super layoutSubviews];

self.label.frame = self.bounds;

self.label.font = [UIFont systemFontOfSize:self.frame.size.width * 0.2];
self.waveLayer.frame = self.bounds;
self.layer.cornerRadius = self.frame.size.width * 0.5;
self.layer.borderWidth = self.frame.size.width * 0.04;
}

- (void)setup
{
_threshold = 200;
_threshold = 300;

self.waveLayer = [CAShapeLayer new];
self.waveLayer.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.6].CGColor;
Expand All @@ -101,14 +103,12 @@ - (void)setup

self.backgroundColor = [UIColor whiteColor];

self.layer.cornerRadius = 40;

self.layer.borderColor = [[UIColor greenColor] colorWithAlphaComponent:0.7].CGColor;
self.layer.borderWidth = 3;
self.clipsToBounds = YES;

self.label = [UILabel new];
self.label.textColor = [UIColor blackColor];
self.label.font = [UIFont systemFontOfSize:12];
self.label.textAlignment = NSTextAlignmentCenter;
[self addSubview:self.label];

Expand Down Expand Up @@ -189,15 +189,18 @@ - (void)setCurrentWaveLayerPath

// 正弦曲线公式:y=Asin(ωx+φ)+k

CGFloat wh = 80.f;
CGFloat wh = self.bounds.size.width;
if (0 == wh) {
return;
}
CGFloat persent = 1 - MIN(1, self.memory / _threshold);
CGFloat s_ω = 2.0 * M_PI / wh;
CGFloat s_ω = 2 * M_PI / wh;
CGFloat s_k = wh * persent;
CGFloat s_φ = 0;
CGFloat s_A = 1.3f;
CGFloat s_A = 1.3f * wh / 80.f;

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(-40, wh * persent)];
[path moveToPoint:CGPointMake(0, wh * persent)];

static CGFloat controlX = 0;
s_φ = controlX;
Expand All @@ -208,7 +211,7 @@ - (void)setCurrentWaveLayerPath
[path addLineToPoint:CGPointMake(x, y)];
}

[path addLineToPoint:CGPointMake(wh + 40, 0)];
[path addLineToPoint:CGPointMake(wh, 0)];
[path addLineToPoint:CGPointMake(0, 0)];
[path closePath];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define OOMStaticsInfoCenter_h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef void (^StatisticsInfoBlock)(NSInteger memorySize_M);

Expand All @@ -34,6 +35,8 @@ typedef void (^StatisticsInfoBlock)(NSInteger memorySize_M);
@property (nonatomic, copy) StatisticsInfoBlock statisticsInfoBlock;

- (void)showMemoryIndicatorView:(BOOL)yn;
- (void)setupMemoryIndicatorFrame:(CGRect)frame;

-(void)updateMemory;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,21 @@ - (double)appMaxMemory

- (void)showMemoryIndicatorView:(BOOL)yn
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if (yn) {
if (!_indicatorView) {
_indicatorView = [MemoryIndicator indicator];
}
[_indicatorView setThreshhold:overflow_limit];
if (yn) {
if (!_indicatorView) {
_indicatorView = [MemoryIndicator indicator];
}
[_indicatorView show:yn];
}];
[_indicatorView setThreshhold:overflow_limit];
}
[_indicatorView show:yn];
}

- (void)setupMemoryIndicatorFrame:(CGRect)frame
{
if (!_indicatorView) {
[self showMemoryIndicatorView:YES];
}
_indicatorView.frame = frame;
}

@end

0 comments on commit ef85c45

Please sign in to comment.