Search code examples
iosswiftuiimageviewontouch

control multiple buttons with one swipe gesture swift


I have array of UIImageView that printed on the main View (as subviews) in a matrix.

That UIImageViews interact while I am tap on them (work like a pixel when I touch one of them it turn on (move from black to green)

but I want to do it with swipe gesture so i can with one swipe trigger more than one "pixel" (UIImageView)

I found this for android triggering-multiple-buttonsonclick-event-with-one-swipe-gesture and I wonder if there is something like that in ios with swift that recognise general touch (not tap or swipe) so I can looks for it.

The main purpose of all of this is to draw "shapes" on matrix of pixels with one swipe gestures.

If there is another way that you think will help I will be happy to here about it.

Many thanks


Solution

  • i Manage to do the the swipe action using touchesMoved and touchesEnded

    while the main idea is to invoke the UIIMageViews using the Coordinate of the touch and compare it to the to the UIImageViews Coordinates in the touchesMoved function

    using flags to disable already edited UIIMageViews (while i am in the same touch session , the finger still on the screen) and refresh the UIImageViews to be editable again in the touchesEnded

        func swipeTouches(touches: NSSet!) {
                // Get the first touch and its location in this view controller's view coordinate system
                let touch = touches.allObjects[0] as! UITouch
                let touchLocation = touch.locationInView(self.view)
    
                for pixel in pixelArrays {
                    // Convert the location of the obstacle view to this view controller's view coordinate system
                    let pixelViewFrame = self.view.convertRect(pixel.pixelImage.frame, fromView: pixel.pixelImage.superview)
    
                    // Check if the touch is inside the obstacle view
                    if CGRectContainsPoint(pixelViewFrame, touchLocation) {
                        // check if the pixel is Editable
                        if(!pixel.isEditable){
                            let index = pixel.index
                            pixelArrays.insert(updatePixel(index) , atIndex: index)
                        }
                    }
                }
            }
    

    the only problem that i have now that if the swipe begin on one of the UIImageViews the touchesMoved function consider it the the view to looks for the coordinate and the other UIImageViews are not effected

    my idea to solve it is to add layer on top all of the UIImageViews and disable the tap recognition that they alredy have and implement the tap also with the Coordinates way.

    i will be happy to hear if there is another way to do it

    Update : i mange to solve the problem above by sort of what i wrote but instead of add another layer i disable the touch on all of the UIImageViews and invoke them using the Coordinates of the touch and them

    many thanks