Implement zoom and pan in touchscreen mode

This commit is contained in:
Cameron Gutman 2020-11-01 20:22:01 -06:00
parent 0d75dd4efb
commit e809afdd9e
2 changed files with 32 additions and 5 deletions

View File

@ -15,9 +15,9 @@
#if TARGET_OS_TV #if TARGET_OS_TV
@import GameController; @import GameController;
@interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, EdgeDetectionDelegate, InputPresenceDelegate, UserInteractionDelegate> @interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, EdgeDetectionDelegate, InputPresenceDelegate, UserInteractionDelegate, UIScrollViewDelegate>
#else #else
@interface StreamFrameViewController : UIViewController <ConnectionCallbacks, EdgeDetectionDelegate, InputPresenceDelegate, UserInteractionDelegate> @interface StreamFrameViewController : UIViewController <ConnectionCallbacks, EdgeDetectionDelegate, InputPresenceDelegate, UserInteractionDelegate, UIScrollViewDelegate>
#endif #endif
@property (nonatomic) StreamConfiguration* streamConfig; @property (nonatomic) StreamConfiguration* streamConfig;

View File

@ -21,6 +21,7 @@
@implementation StreamFrameViewController { @implementation StreamFrameViewController {
ControllerSupport *_controllerSupport; ControllerSupport *_controllerSupport;
StreamManager *_streamMan; StreamManager *_streamMan;
TemporarySettings *_settings;
NSTimer *_inactivityTimer; NSTimer *_inactivityTimer;
NSTimer *_statsUpdateTimer; NSTimer *_statsUpdateTimer;
UITapGestureRecognizer *_menuGestureRecognizer; UITapGestureRecognizer *_menuGestureRecognizer;
@ -30,6 +31,7 @@
UILabel *_tipLabel; UILabel *_tipLabel;
UIActivityIndicatorView *_spinner; UIActivityIndicatorView *_spinner;
StreamView *_streamView; StreamView *_streamView;
UIScrollView *_scrollView;
BOOL _userIsInteracting; BOOL _userIsInteracting;
} }
@ -59,6 +61,8 @@
[UIApplication sharedApplication].idleTimerDisabled = YES; [UIApplication sharedApplication].idleTimerDisabled = YES;
_settings = [[[DataManager alloc] init] getSettings];
_stageLabel = [[UILabel alloc] init]; _stageLabel = [[UILabel alloc] init];
[_stageLabel setUserInteractionEnabled:NO]; [_stageLabel setUserInteractionEnabled:NO];
[_stageLabel setText:[NSString stringWithFormat:@"Starting %@...", self.streamConfig.appName]]; [_stageLabel setText:[NSString stringWithFormat:@"Starting %@...", self.streamConfig.appName]];
@ -135,12 +139,35 @@
name: UIApplicationDidEnterBackgroundNotification name: UIApplicationDidEnterBackgroundNotification
object: nil]; object: nil];
// 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:_streamView];
}
[self.view addSubview:_stageLabel]; [self.view addSubview:_stageLabel];
[self.view addSubview:_spinner]; [self.view addSubview:_spinner];
[self.view addSubview:_tipLabel]; [self.view addSubview:_tipLabel];
} }
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return _streamView;
}
- (void)willMoveToParentViewController:(UIViewController *)parent { - (void)willMoveToParentViewController:(UIViewController *)parent {
// Only cleanup when we're being destroyed // Only cleanup when we're being destroyed
if (parent == nil) { if (parent == nil) {
@ -276,8 +303,7 @@
[self->_streamView showOnScreenControls]; [self->_streamView showOnScreenControls];
TemporarySettings* settings = [[[DataManager alloc] init] getSettings]; if (self->_settings.statsOverlay) {
if (settings.statsOverlay) {
self->_statsUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f self->_statsUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self target:self
selector:@selector(updateStatsOverlay) selector:@selector(updateStatsOverlay)
@ -433,6 +459,7 @@
- (void) videoContentShown { - (void) videoContentShown {
[_spinner stopAnimating]; [_spinner stopAnimating];
[self.view setBackgroundColor:[UIColor blackColor]];
} }
- (void)didReceiveMemoryWarning - (void)didReceiveMemoryWarning