Просмотр исходного кода

Add swipe gestures to select a more shallow or deeper view

Tanner Bennett лет назад: 6
Родитель
Сommit
be02b89d9b

+ 29 - 2
Classes/ExplorerInterface/FLEXExplorerViewController.m

@@ -449,6 +449,17 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
         initWithTarget:self action:@selector(handleToolbarDetailsTapGesture:)
     ];
     [toolbar.selectedViewDescriptionContainer addGestureRecognizer:self.detailsTapGR];
+    // Swipe gestures for selecting deeper / higher views at a point
+    UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]
+        initWithTarget:self action:@selector(handleChangeViewAtPointGesture:)
+    ];
+    UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc]
+        initWithTarget:self action:@selector(handleChangeViewAtPointGesture:)
+    ];
+    leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
+    rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
+    [toolbar.selectedViewDescriptionContainer addGestureRecognizer:leftSwipe];
+    [toolbar.selectedViewDescriptionContainer addGestureRecognizer:rightSwipe];
     
     // Long press gesture to present tabs manager
     [toolbar.globalsItem addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
@@ -586,6 +597,22 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     }
 }
 
+- (void)handleChangeViewAtPointGesture:(UISwipeGestureRecognizer *)sender {
+    NSInteger max = self.viewsAtTapPoint.count - 1;
+    NSInteger currentIdx = [self.viewsAtTapPoint indexOfObject:self.selectedView];
+    switch (sender.direction) {
+        case UISwipeGestureRecognizerDirectionLeft:
+            self.selectedView = self.viewsAtTapPoint[MIN(max, currentIdx + 1)];
+            break;
+        case UISwipeGestureRecognizerDirectionRight:
+            self.selectedView = self.viewsAtTapPoint[MAX(0, currentIdx - 1)];
+            break;
+            
+        default:
+            break;
+    }
+}
+
 - (void)updateOutlineViewsForSelectionPoint:(CGPoint)selectionPointInWindow {
     [self removeAndClearOutlineViews];
     
@@ -646,8 +673,8 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     // Select in the window that would handle the touch, but don't just use the result of
     // hitTest:withEvent: so we can still select views with interaction disabled.
     // Default to the the application's key window if none of the windows want the touch.
-    UIWindow *windowForSelection = [UIApplication.sharedApplication keyWindow];
-    for (UIWindow *window in [FLEXUtility allWindows].reverseObjectEnumerator) {
+    UIWindow *windowForSelection = UIApplication.sharedApplication.keyWindow;
+    for (UIWindow *window in FLEXUtility.allWindows.reverseObjectEnumerator) {
         // Ignore the explorer's own window.
         if (window != self.view.window) {
             if ([window hitTest:tapPointInWindow withEvent:nil]) {

+ 2 - 2
Classes/Utility/FLEXUtility.h

@@ -83,6 +83,8 @@ NS_INLINE CGRect FLEXRectSetHeight(CGRect r, CGFloat height) {
 /// The key window of the app, if it is not a \c FLEXWindow.
 /// If it is, then \c FLEXWindow.previousKeyWindow is returned.
 @property (nonatomic, readonly, class) UIWindow *appKeyWindow;
+/// @return the result of +[UIWindow allWindowsIncludingInternalWindows:onlyVisibleWindows:]
+@property (nonatomic, readonly, class) NSArray<UIWindow *> *allWindows;
 /// The first active \c UIWindowScene of the app.
 @property (nonatomic, readonly, class) UIWindowScene *activeScene API_AVAILABLE(ios(13.0));
 /// @return top-most view controller of the given window
@@ -111,8 +113,6 @@ NS_INLINE CGRect FLEXRectSetHeight(CGRect r, CGFloat height) {
 + (BOOL)isValidJSONData:(NSData *)data;
 + (NSData *)inflatedDataFromCompressedData:(NSData *)compressedData;
 
-+ (NSArray<UIWindow *> *)allWindows;
-
 // Swizzling utilities
 
 + (SEL)swizzledSelectorForSelector:(SEL)selector;