mirror of
https://github.com/joeblau/COSTouchVisualizer.git
synced 2024-10-26 12:44:44 +03:00
Merge branch 'master' of github.com:conopsys/COSTouchVisualizer
This commit is contained in:
commit
80098140b1
2
Classes/COSTouchVisualizerWindow.h
Normal file → Executable file
2
Classes/COSTouchVisualizerWindow.h
Normal file → Executable file
@ -23,4 +23,6 @@
|
||||
@property (nonatomic, strong) UIColor *rippleStrokeColor;
|
||||
@property (nonatomic, strong) UIColor *rippleFillColor;
|
||||
|
||||
@property (nonatomic) BOOL stationaryMorphEnabled; // default: YES
|
||||
|
||||
@end
|
||||
|
52
Classes/COSTouchVisualizerWindow.m
Normal file → Executable file
52
Classes/COSTouchVisualizerWindow.m
Normal file → Executable file
@ -81,19 +81,14 @@
|
||||
self.rippleStrokeColor = [UIColor whiteColor];
|
||||
self.rippleFillColor = [UIColor blueColor];
|
||||
|
||||
self.overlayWindow = [[UIWindow alloc] initWithFrame:self.frame];
|
||||
self.overlayWindow.rootViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
|
||||
self.overlayWindow.userInteractionEnabled = NO;
|
||||
self.overlayWindow.windowLevel = UIWindowLevelStatusBar;
|
||||
self.overlayWindow.backgroundColor = [UIColor clearColor];
|
||||
self.overlayWindow.hidden = NO;
|
||||
|
||||
self.touchAlpha = 0.5;
|
||||
self.fadeDuration = 0.3;
|
||||
|
||||
self.rippleAlpha = 0.2;
|
||||
self.rippleFadeDuration = 0.2;
|
||||
|
||||
|
||||
self.stationaryMorphEnabled = YES;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(screenConnect:)
|
||||
name:UIScreenDidConnectNotification
|
||||
@ -112,6 +107,7 @@
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenDidConnectNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenDidDisconnectNotification object:nil];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (UIImage *)touchImage {
|
||||
@ -208,13 +204,11 @@
|
||||
case UITouchPhaseMoved:
|
||||
{
|
||||
// Generate ripples
|
||||
COSTouchSpotView *rippleView = (COSTouchSpotView *)[self.overlayWindow.rootViewController.view viewWithTag:touch.hash];
|
||||
|
||||
rippleView = [[COSTouchSpotView alloc] initWithImage:self.rippleImage];
|
||||
[self.overlayWindow.rootViewController.view addSubview:rippleView];
|
||||
|
||||
COSTouchSpotView *rippleView = [[COSTouchSpotView alloc] initWithImage:self.rippleImage];
|
||||
[self.overlayWindow addSubview:rippleView];
|
||||
|
||||
rippleView.alpha = self.rippleAlpha;
|
||||
rippleView.center = [touch locationInView:self.overlayWindow.rootViewController.view];
|
||||
rippleView.center = [touch locationInView:self.overlayWindow];
|
||||
|
||||
[UIView animateWithDuration:self.rippleFadeDuration
|
||||
delay:0.0
|
||||
@ -229,7 +223,7 @@
|
||||
}
|
||||
case UITouchPhaseStationary:
|
||||
{
|
||||
COSTouchSpotView *touchView = (COSTouchSpotView *)[self.overlayWindow.rootViewController.view viewWithTag:touch.hash];
|
||||
COSTouchSpotView *touchView = (COSTouchSpotView *)[self.overlayWindow viewWithTag:touch.hash];
|
||||
|
||||
if (touch.phase != UITouchPhaseStationary && touchView != nil && [touchView isFadingOut]) {
|
||||
[self.timer invalidate];
|
||||
@ -239,14 +233,16 @@
|
||||
|
||||
if (touchView == nil && touch.phase != UITouchPhaseStationary) {
|
||||
touchView = [[COSTouchSpotView alloc] initWithImage:self.touchImage];
|
||||
[self.overlayWindow.rootViewController.view addSubview:touchView];
|
||||
[self.overlayWindow addSubview:touchView];
|
||||
|
||||
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(performMorph:) userInfo:touchView repeats:YES];
|
||||
if (self.stationaryMorphEnabled) {
|
||||
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(performMorph:) userInfo:touchView repeats:YES];
|
||||
}
|
||||
}
|
||||
|
||||
if (![touchView isFadingOut]) {
|
||||
touchView.alpha = self.touchAlpha;
|
||||
touchView.center = [touch locationInView:self.overlayWindow.rootViewController.view];
|
||||
touchView.center = [touch locationInView:self.overlayWindow];
|
||||
touchView.tag = touch.hash;
|
||||
touchView.timestamp = touch.timestamp;
|
||||
touchView.shouldAutomaticallyRemoveAfterTimeout = [self shouldAutomaticallyRemoveFingerTipForTouch:touch];
|
||||
@ -272,6 +268,18 @@
|
||||
#pragma mark -
|
||||
#pragma mark Private
|
||||
|
||||
- (UIWindow *)overlayWindow {
|
||||
if (!_overlayWindow) {
|
||||
_overlayWindow = [[UIWindow alloc] initWithFrame:self.frame];
|
||||
_overlayWindow.userInteractionEnabled = NO;
|
||||
_overlayWindow.windowLevel = UIWindowLevelStatusBar;
|
||||
_overlayWindow.backgroundColor = [UIColor clearColor];
|
||||
_overlayWindow.hidden = NO;
|
||||
}
|
||||
|
||||
return _overlayWindow;
|
||||
}
|
||||
|
||||
- (void)scheduleFingerTipRemoval {
|
||||
if (self.fingerTipRemovalScheduled) return;
|
||||
self.fingerTipRemovalScheduled = YES;
|
||||
@ -289,19 +297,19 @@
|
||||
NSTimeInterval now = [[NSProcessInfo processInfo] systemUptime];
|
||||
const CGFloat REMOVAL_DELAY = 0.2;
|
||||
|
||||
for (COSTouchSpotView *touchView in [self.overlayWindow.rootViewController.view subviews]) {
|
||||
for (COSTouchSpotView *touchView in [self.overlayWindow subviews]) {
|
||||
if (![touchView isKindOfClass:[COSTouchSpotView class]]) continue;
|
||||
|
||||
if (touchView.shouldAutomaticallyRemoveAfterTimeout && now > touchView.timestamp + REMOVAL_DELAY)
|
||||
[self removeFingerTipWithHash:touchView.tag animated:YES];
|
||||
}
|
||||
|
||||
if ([[self.overlayWindow.rootViewController.view subviews] count])
|
||||
if ([[self.overlayWindow subviews] count])
|
||||
[self scheduleFingerTipRemoval];
|
||||
}
|
||||
|
||||
- (void)removeFingerTipWithHash:(NSUInteger)hash animated:(BOOL)animated {
|
||||
COSTouchSpotView *touchView = (COSTouchSpotView *)[self.overlayWindow.rootViewController.view viewWithTag:hash];
|
||||
COSTouchSpotView *touchView = (COSTouchSpotView *)[self.overlayWindow viewWithTag:hash];
|
||||
if (touchView == nil)
|
||||
return;
|
||||
|
||||
@ -401,4 +409,4 @@
|
||||
|
||||
@implementation COSTouchSpotView
|
||||
|
||||
@end
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user