Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions GDPerformanceView/GDPerformanceMonitoring/GDPerformanceView.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#import "GDMarginLabel.h"
#import "GDWindowViewController.h"

static const CGFloat kDefaultHeight = 20.f;

@interface GDPerformanceView ()

@property (nonatomic, strong) CADisplayLink *displayLink;
Expand Down Expand Up @@ -265,7 +267,7 @@ + (CGRect)windowFrame {
CGRect frame = CGRectZero;
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
if (window) {
frame = CGRectMake(0.0f, 0.0f, CGRectGetWidth(window.bounds), 20.0f);
frame = CGRectMake(0.0f, 0.0f, CGRectGetWidth(window.bounds), kDefaultHeight);
}
return frame;
}
Expand All @@ -287,17 +289,40 @@ - (void)updateMonitoringLabelWithFPS:(int)fpsValue CPU:(float)cpuValue {

- (void)layoutTextLabel {
CGFloat windowWidth = CGRectGetWidth(self.bounds);
CGFloat windowHeight = CGRectGetHeight(self.bounds);
CGSize labelSize = [self.monitoringTextLabel sizeThatFits:CGSizeMake(windowWidth, windowHeight)];

[self.monitoringTextLabel setFrame:CGRectMake((windowWidth - labelSize.width) / 2.0f, (windowHeight - labelSize.height) / 2.0f, labelSize.width, labelSize.height)];
CGSize labelSize = [self.monitoringTextLabel sizeThatFits:CGSizeMake(windowWidth, kDefaultHeight)];
CGFloat safeAreaOffset = [self safeAreaTopMargin];

CGRect frame = CGRectMake((windowWidth - labelSize.width) / 2.0f,
safeAreaOffset + ((kDefaultHeight - labelSize.height) / 2.0f),
labelSize.width,
labelSize.height);
[self.monitoringTextLabel setFrame:frame];
}

- (void)layoutWindow {
[self setFrame:[GDPerformanceView windowFrame]];
CGRect frame = [GDPerformanceView windowFrame];
frame.size.height += [self safeAreaTopMargin];
[self setFrame:frame];
[self layoutTextLabel];
}

- (CGFloat)safeAreaTopMargin {
CGFloat safeAreaTopMargin = 0;

SEL safeAreaInsetsSel = sel_getUid("safeAreaInsets");
NSMethodSignature* methodSignature = [self methodSignatureForSelector:safeAreaInsetsSel];
if (methodSignature && ([methodSignature methodReturnLength] == sizeof(UIEdgeInsets))) {
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
invocation.selector = safeAreaInsetsSel;
[invocation invokeWithTarget:self];
UIEdgeInsets safeAreaInsets;
[invocation getReturnValue:&safeAreaInsets];
safeAreaTopMargin = safeAreaInsets.top;
}

return safeAreaTopMargin;
}

- (void)configureVersionsString {
if (!self.appVersionHidden || !self.deviceVersionHidden) {
NSString *applicationVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
Expand Down