From e809afdd9e1967d7ca7ca22cb47e8e099b77589c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 1 Nov 2020 20:22:01 -0600 Subject: [PATCH] Implement zoom and pan in touchscreen mode --- .../StreamFrameViewController.h | 4 +-- .../StreamFrameViewController.m | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Limelight/ViewControllers/StreamFrameViewController.h b/Limelight/ViewControllers/StreamFrameViewController.h index 7ecb3fa6..65a3c34a 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.h +++ b/Limelight/ViewControllers/StreamFrameViewController.h @@ -15,9 +15,9 @@ #if TARGET_OS_TV @import GameController; -@interface StreamFrameViewController : GCEventViewController +@interface StreamFrameViewController : GCEventViewController #else -@interface StreamFrameViewController : UIViewController +@interface StreamFrameViewController : UIViewController #endif @property (nonatomic) StreamConfiguration* streamConfig; diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 571880ac..bfbd4096 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -21,6 +21,7 @@ @implementation StreamFrameViewController { ControllerSupport *_controllerSupport; StreamManager *_streamMan; + TemporarySettings *_settings; NSTimer *_inactivityTimer; NSTimer *_statsUpdateTimer; UITapGestureRecognizer *_menuGestureRecognizer; @@ -30,6 +31,7 @@ UILabel *_tipLabel; UIActivityIndicatorView *_spinner; StreamView *_streamView; + UIScrollView *_scrollView; BOOL _userIsInteracting; } @@ -59,6 +61,8 @@ [UIApplication sharedApplication].idleTimerDisabled = YES; + _settings = [[[DataManager alloc] init] getSettings]; + _stageLabel = [[UILabel alloc] init]; [_stageLabel setUserInteractionEnabled:NO]; [_stageLabel setText:[NSString stringWithFormat:@"Starting %@...", self.streamConfig.appName]]; @@ -135,12 +139,35 @@ name: UIApplicationDidEnterBackgroundNotification object: nil]; - [self.view addSubview:_streamView]; + // Only enable scroll and zoom in absolute touch mode + if (_settings.absoluteTouchMode) { + _scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; +#if !TARGET_OS_TV + [_scrollView.panGestureRecognizer setMinimumNumberOfTouches:2]; +#endif + [_scrollView setShowsHorizontalScrollIndicator:NO]; + [_scrollView setShowsVerticalScrollIndicator:NO]; + [_scrollView setDelegate:self]; + [_scrollView setMaximumZoomScale:10.0f]; + + // Add StreamView inside a UIScrollView for absolute mode + [_scrollView addSubview:_streamView]; + [self.view addSubview:_scrollView]; + } + else { + // Add StreamView directly in relative mode + [self.view addSubview:_streamView]; + } + [self.view addSubview:_stageLabel]; [self.view addSubview:_spinner]; [self.view addSubview:_tipLabel]; } +- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { + return _streamView; +} + - (void)willMoveToParentViewController:(UIViewController *)parent { // Only cleanup when we're being destroyed if (parent == nil) { @@ -276,8 +303,7 @@ [self->_streamView showOnScreenControls]; - TemporarySettings* settings = [[[DataManager alloc] init] getSettings]; - if (settings.statsOverlay) { + if (self->_settings.statsOverlay) { self->_statsUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateStatsOverlay) @@ -433,6 +459,7 @@ - (void) videoContentShown { [_spinner stopAnimating]; + [self.view setBackgroundColor:[UIColor blackColor]]; } - (void)didReceiveMemoryWarning