[vlc-commits] test: iosvlc: add pinch gesture recognizer

Alexandre Janniaux git at videolan.org
Sat Mar 13 13:06:32 UTC 2021


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Tue Feb 16 16:01:02 2021 +0100| [904998afec0b2d4192e877c19c7e5295bcaf4c67] | committer: Alexandre Janniaux

test: iosvlc: add pinch gesture recognizer

Allow the test application to be resized to test the behaviour of
libvlccore resizing. Later, this should probably be enabled by a feature
flag or an environment variable.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=904998afec0b2d4192e877c19c7e5295bcaf4c67
---

 test/iosvlc.m | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/test/iosvlc.m b/test/iosvlc.m
index 23b2c236b4..12c1391343 100644
--- a/test/iosvlc.m
+++ b/test/iosvlc.m
@@ -37,11 +37,47 @@
     libvlc_instance_t *_libvlc;
     UIWindow *window;
     UIView *subview;
+    UIPinchGestureRecognizer *_pinchRecognizer;
+
+    CGRect _pinchRect;
+    CGPoint _pinchOrigin;
+    CGPoint _pinchPreviousCenter;
 }
 @end
 
 
 @implementation AppDelegate
+- (void)pinchRecognized:(UIPinchGestureRecognizer *)pinchRecognizer
+{
+    UIGestureRecognizerState state = [pinchRecognizer state];
+
+    switch (state)
+    {
+        case UIGestureRecognizerStateBegan:
+            _pinchRect = [subview frame];
+            _pinchOrigin = [pinchRecognizer locationInView:nil];
+            _pinchPreviousCenter = [subview center];
+            return;
+        case UIGestureRecognizerStateEnded:
+            return;
+        case UIGestureRecognizerStateChanged:
+            break;
+        default:
+            return;
+    }
+
+    CGFloat scale = pinchRecognizer.scale;
+    CGRect viewBounds = _pinchRect;
+    if (scale >= 1.0 && (viewBounds.size.width == 0 || viewBounds.size.height == 0))
+            viewBounds.size.width = viewBounds.size.height = 1;
+    viewBounds.size.width *= scale;
+    viewBounds.size.height *= scale;
+    subview.frame = viewBounds;
+    CGPoint newPosition = [pinchRecognizer locationInView:nil];
+    subview.center = CGPointMake(
+            _pinchPreviousCenter.x + newPosition.x - _pinchOrigin.x,
+            _pinchPreviousCenter.y + newPosition.y - _pinchOrigin.y);
+}
 /* Called after application launch */
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
@@ -76,6 +112,10 @@
     [window addSubview:subview];
     [window makeKeyAndVisible];
 
+    _pinchRecognizer = [[UIPinchGestureRecognizer alloc]
+        initWithTarget:self action:@selector(pinchRecognized:)];
+    [window addGestureRecognizer:_pinchRecognizer];
+
     /* Start glue interface, see code below */
     libvlc_add_intf(_libvlc, "ios_interface,none");
 



More information about the vlc-commits mailing list