Guidance - Custom UICollectionView animation - ios

I am looking for guidance with how to approach the following animation scenario.
I have UICollectionView with a custom circular UICollectionViewLayout subclassed layout. There are (circular) images around the perimeter of the circle and a 50% larger (circular) image in the center of the circle.
When the user taps one of the perimeter images, I want the tapped on image to move toward the center (becoming 50% bigger) and sort of "connect with" the center image. I then want the two images to float to the top of the view. (The bottom portion of the view will then be a context of things related to the two joined images).
If this makes sense to anyone, I'd really appreciate a starting point of some kind.
By the way, I'm an old developer but new to iOS and developing in Swift (but can read Objective-C).
Thanks!

I solved this using a visual trick. Of course, I'm sure there's a better way.
When one of the perimeter circles is tapped, I transition to a view controller that immediately creates a duplicate of the center circle and the tapped circle in their former locations, making it appear that the other elements disappeared.
I then simultaneously animate the tapped circle to the center and the center image to the top of the view. I enlarge the tapped circle briefly and then animate it to the top of the view next to the center circle restoring the tapped image's original size.
Not elegant but it works.

Related

Floating content of UIScrollView when smaller

I'm trying to make kind of collage, so I want to resize image and drag it to any position of scroll view. Currently I can drag image only when it is bigger than scroll view. But when it is smaller than it sticks to top left corner. Yes, I can use scrollViewDidZoom to move image to center for example, but it is not what I'm looking for. For example I want to allow users to drag an image to any position of the scroll view, like this
To do that I just merge big empty image with my image I want to move. Looks like a bad solution, but it working as I wanted

How to implement scaling by dragging view edges/corners like Apply Official Photos app crop control?

The apple official photos application have a edit function which you can crop photos. I would like to implement a similar control for cropping photos. I would like to know how to implement the resizing of the crop mask.
The resizing of the crop mask have the following requirements.
The crop mask can only be resizing by dragging edges or corners.
The anchor point of scaling is opposite the the start edge or corner.
The crop mask can have aspect ratio lock.
The crop mask should not go belong a restricted bounds.
I have done the first 3 requirements, but the 4 requirement is troubling me. Consider a case where the crop mask is at its minimal size at the restricted bounds box bottom left corner. Dragging the top edges will make the view scale with anchor point at the bottom left corner. With this strange behaviour, I think my implementation of changing bounds with opposite anchor point cannot have this behaviour. So I think the apple implementation is different from mine. And I would like to know how these behaviour can be achieved.
The question is what procedure have you even taken.
I would suggest this is done with a simple UIScrollView. Your "crop mask" can be the scroll view which may be resized and repositioned by dragging the corners of it. The scroll view must have the "clip subviews" disabled so you may see the content view outside the scroll view (the content view being the actual image).
So this procedure will already save you all the trouble with bounds when scrolling the image. Moving the scroll view will still have a bit of work... Depending on which corner you are dragging you might need to modify the content offset as you seem to have already figured and should give no trouble at all. Then what is left is putting the image into the crop mask when it gets out of bounds which should be done by calling scroll rect to visible for the whole content view frame; if not it can be easily computed manually as well.
You must also override the hit test method so that the scrolling will happen outside the scroll view.

Swift : Create region to UIPanGesture

I have this design here : http://imgur.com/XHMBUdj
I would like to allocate the left half of the screen(splitting vertically) to panning up and down for the blue bars and allocate the right half of the screen(splitting vertically) to panning up and down for the red bars.
I can already use UIPanGestureRecognizer, however, I just need help making the region in which if the user pans on the right side of the screen, "this" happens and if the user pans on the left side, "this" happens.
A friend of mine recommended using UIBezierPath. Could someone help me out? Code will be much appreciated!
I looks like it would be easier to have two UIPanGestureRecognizers.
In your view, you can add a subview that take up the left half on the screen that contains the blue bars and the microphone and add another subview that is on the right half of the screen containing the red bars and the music icon.
Then you can create two separate UIPanGestureRecognizers and add one to each of the views. Then each side will have its one recognizer that will take care of the side detection for you.

Leaping image just before Constraint animation

I'm using Constraints within my app and have have a reasonable level of success so far; everything visual object in the gif below is Constrained.
The issue is that when selected, tiles leap to another location before animating to the final, correct destination.
From a code perspective, on a tile click, higher priority positioning Constraints are applied to the tile, the tile is added as a subview to the blue area, then animation is performed.
Can anyone shed a little light on what's happening here?
Thanks
Based on the behavior I'm seeing in your gif, I would guess that when you move the tile views between superviews (the blue area vs. the larger white area), the view jumps to it's current frame position (within the coordinate system of the old superview), but now in the coordinate system of the new superview.
The solution, I think, would be to translate the final position in the new superview to a position in the current superview, perform the animation, and only when the animation completes would you move the view to it's new superview.
Does that make sense?

Fade UIImageView as it approaches the edges of a UIScrollView

I have a UIScrollView over an image at the bottom of my app that acts as a dock with icons that can be scrolled through horizontally. Instead of the harsh edges of the UIScrollView, I would like the icons to fade out for a more aesthetically pleasing look. Being new to iOS development, I don't know if either of these would be valid options:
Create a faded image to use as an overlay on the scrollview so the
icons only appear through the visible portion.
Actually change the
alpha of the images based on their distance from the center (or from
each edge).
I suspect the first idea would be the most simple, but I'd like to throw this out there for any other ideas.
Note: I did see this tutorial, however that technique assumes that the background is a solid color. If I were to do it programatically, I would probably need to fade the individual images.
You can definitely implement something along the lines of #2. It'd be something similar to what the tutorial describes. The alpha transition however won't be as smooth as using the gradient layer mentioned in the tutorial or using an image since the entire icon would have the same alpha. How much discernible the difference is depends on the size of your icons. Smaller icons, very few will be able to tell the difference. Larger icons the difference would be quite clear.
You'd have to implement the
(void)scrollViewDidScroll:(UIScrollView *)scrollView
method in your scroll view's delegate class. This method will get called every time the scroll view changes the location of its content. In this method you can call its subviews and adjust their alphas as required. To optimize it a bit instead of calling the alpha adjustments on all the elements you can just update the subviews which are still partially/completely visible.
EDIT: to figure out which views to adjust you'll use the contentOffset property of the scrollView that gets passed as a parameter in the above method.

Resources