Search code examples
objective-cxcodeuiscrollviewdrag-and-dropdropshadow

Drag And Swap Two UIScrollViews (Hover & Swap Effect)


I am creating a photo editor in my app and working on a multiple picture layout option.

Currently when the user takes a picture, I display their image in UIImageView nested in a UIScrollView. The reason I nest it in a UIScrollView is so I can pan and zoom.

In the situation where the user selects duo layout mode, the app puts 2 images side by side (so 2 UIScrollViews).

If they hold a finger on one UIScrollView I want to raise the UIScrollView up a tad and give it a drop shadow.

I have a long way of doing this, but I was curious if there was anything in the native libraries that will let me automatically create this hover effect for dragging a view class.

Thanks

enter image description here


Solution

  • No, there isn't any preexisting functionality for this. You can add shadow and animate a "lift" motion yourself with something like this:

    // define dragged somewhere as the UIView subclass of your choosing
    dragged.layer.shadowColor = [UIColor blackColor].CGColor;
    dragged.layer.shadowOffset = CGSizeMake(-2, 2);
    dragged.layer.masksToBounds = NO;
    dragged.layer.shadowRadius = 4;
    dragged.layer.shadowOpacity = .7;
    [UIView animateWithDuration:.2 delay:0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{self.draggedPhoto.transform = CGAffineTransformMakeScale(1.2, 1.2);}
                     completion:nil];