From aa6453ca256e11c044c8c2e13483eb85112faf90 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Thu, 15 Aug 2019 11:30:01 +0200 Subject: [PATCH] also show fingertips when capturing screen On iOS 11 and higher it's possible to record the screen on the device itself. Making touches visible in that scenario is also very useful. --- MBFingerTipWindow.m | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/MBFingerTipWindow.m b/MBFingerTipWindow.m index 130a265..c3f4257 100644 --- a/MBFingerTipWindow.m +++ b/MBFingerTipWindow.m @@ -92,6 +92,12 @@ - (void)MBFingerTipWindow_commonInit name:UIScreenDidDisconnectNotification object:nil]; + if (@available(iOS 11.0, *)) + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(screenCaptureChanged:) + name:UIScreenCapturedDidChangeNotification + object:nil]; + // Set up active now, in case the screen was present before the window was created (or application launched). // [self updateFingertipsAreActive]; @@ -99,8 +105,10 @@ - (void)MBFingerTipWindow_commonInit - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenDidConnectNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenDidDisconnectNotification object:nil]; + if (@available(iOS 11.0, *)) + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenCapturedDidChangeNotification object:nil]; } #pragma mark - @@ -156,12 +164,12 @@ - (UIImage *)touchImage - (void)setAlwaysShowTouches:(BOOL)flag { - if (_alwaysShowTouches != flag) - { - _alwaysShowTouches = flag; + if (_alwaysShowTouches != flag) + { + _alwaysShowTouches = flag; [self updateFingertipsAreActive]; - } + } } #pragma mark - @@ -177,6 +185,11 @@ - (void)screenDisconnect:(NSNotification *)notification [self updateFingertipsAreActive]; } +- (void)screenCaptureChanged:(NSNotification *)notification +{ + [self updateFingertipsAreActive]; +} + - (BOOL)anyScreenIsMirrored { if ( ! [UIScreen instancesRespondToSelector:@selector(mirroredScreen)]) @@ -186,6 +199,10 @@ - (BOOL)anyScreenIsMirrored { if ([screen mirroredScreen] != nil) return YES; + + if (@available(iOS 11.0, *)) + if ([screen isCaptured]) + return YES; } return NO;