Need help in position images when view going back into place using - ios

Hey everyone I've been stuck on this issue for the past few days. It's pretty hard to describe so I uploaded a video for it on a GitHub repository:
https://github.com/DJSimonSays93/PresentationController
It involves custom view controller transitions using present and the delegates UIViewControllerTransitioningDelegate and UIViewControllerAnimatedTransitioning

The "problem" is straightforward, now let me see if I can describe it in words.
You've got two image views showing, say, the basil image: the one in the scroll view, and the full-screen one when you present. They are both set at Aspect Fill. But the aspect ratio itself is different for these two image views. Therefore, in order to be displayed in Aspect Fill in a different image view, the image shifts in the way it is shown.
The reason you find this upsetting at the end of the dismiss is that you don't notice it happening at the start of the present, but if you slow down your video (you can turn on Slow Animations on the simulator, it will help), you can see it there too:
When you tap an image in the scroll view, there is a jump as the image changes its display for the new image view, and then the image view grows to its true size as the transform is removed (animated).
When you tap the full screen image, the transform is applied (animated) and then there is a jump as the image view is taken away to reveal the old image view that was behind it.
If you make both image view Scale To Fill, that won't happen. Of course then there is a distortion of the image, but it is the same distortion so that the image appears to grow and shrink smoothly right the way through. Try it and you will at least be satisfied by the sense of what I'm saying.
(See https://www.apeth.com/stretch.gif.)
If you don't want to do that, then you will have a lot more work to do; you will need to figure out how to actually compensate for the difference in aspect ratio by changing the aspect ratio of the image to match. Or, you could make the goal size of the fullscreen image view match the aspect ratio of the small image view (and part of it will just end up offscreen).
The point is, you cannot display the same image using Aspect Fill in image view with different aspect ratios and expect the image to appear the same way in both. Either the image needs to be different (to compensate) or the aspect ratios need to be the same.

Related

how to load image from camera for specific/variable sizes?

I have a very simple requirement here but I'm looking for a solution for a while. I want to take a profile picture form the camera roll or camera and display it in two different image views (different sizes). I don't want any of these images stretched or miss any part of the image. If I use aspect to fit, top side of image is cut from smaller image view and some parts missing on the bigger image view. If I set it as scale to fit, it will get stretched!
I'm not sure how some mobile apps work. Do they save different image sizes in their server or they change the size of the image. I saw many posts how to change image size without changing aspect ratio. But I don't think it is possible to avoid stretched effects. I used some of those code to change size of image, it gets stretched all the time.
Is there any way to save the image from camera roll one time with size of 140*200 and one time 160*200? So I can use 140*200 for image views that size. But what if I have different devices and different sizes.

How to correctly use aspect ratio in xcode

So I'm trying to create a user profile that has a user picture that changes sizes with the screen size so it doesn't take up too much space on the smaller iPhone screens.
Everything else in my simulator is sizing correctly during simulation, but the user picture changing size correctly without breaking the ability to stay circular. I tried using aspect ratio, but the picture stays the same size when I simulate on smaller screens. I tried using aspect ratio in relation to the whole view (so that it changes sizes depending on the view), but since the view is rectangular, the picture cannot hold it's ability to stay circular (since it needs to be a square to correctly make the picture circular).
How would I achieve this without creating different views for each phone screen size?
If you set the contentMode of your UIImageView to UIViewContentModeScaleAspectFit, it doesn't matter if the view itself is not square - the image will always show in the right aspect ratio.

iOS full view background image, maintain aspect ratio, control clipping direction

I'm trying to place a background image on a view, using a UIImageView or anything else that will work. I want it to fill the entire view, but maintain the aspect ratio, and allow me to control which side(s) get clipped. I'd like to use Auto Layout if possible (not code).
By setting Auto Layout constraints to keep the UIImageView the full size of the container, and setting Scale Mode to Aspect Fill, I am very close. The only problem is the image is always centered in the view, in that it is cropped on top and bottom in landscape layout and both sides in portrait. I want to be able to control that. I want to be able to "crop just the right side" (keep left edge docked to left of container), or "crop just the top". I have different images and I'll want each one to crop a different way, and possibly I'll allow users to use their own images and select from a few cropping options.
In this image, I currently get the top result, but want the option to get the bottom. The red box shows the visible area in portrait view (roughly):
My question is similar to this one: iOS Aspect Fill Image Resizing with Content Aligned to Left/Top Edge
However, I do not feel it is a duplicate because my needs are different, and I'm also including an image to help explain better. Also, I will not accept an answer of "use different images for portrait vs landscape" because that doesn't really solve the problem. If you understand my question, you would see that you would actually need a different image for every different aspect ratio, pre-cropped in each alignment I want to support. Obviously that's not really a robust solution.

iOS Aspect Fill Image Resizing with Content Aligned to Left/Top Edge

I am developing a universal app for iOS-7. this particular question is specific to iPad only. I want to place an image as background of root view of a View Controller i.e. the image should fill the whole screen. The 1x image has size:768x1024. This works for Portrait orientations as non-retina resolution of iPad is also 768x1024 in portrait. In Landscape however the image does not fit. I have tried using ScaleToFit but since aspect ratio of image is not preserved I can not use ScaleToFit(their are things in image which look odd when not scaled proportionally in both axis). AspectFill resizing seems most suitable for my need, but their is a small problem. As defined in Apple Documentation "The content is resized to completely fill the bounds rectangle, while still preserving the aspect of the content. The content is centered in the axis it exceeds.". I do not want the content to be centered in axis in which it exceeds, I want it to be aligned to top/left edge.
So basically I want two things:
Aspect Fill
The content remains aligned on the Left/Top edge.
Is it possible to achieve this. Any code-snippet will be great.
Thanks
You will have to subclass the View Controller's view and manually scale and align.
Look at the code snippets in THIS answer.
Adjust imageViewXOrigin and imageViewYOrigin to align however you want.
Really the only way to get around the content fill mode is to have two different images, one for each orientation. I'd suggest changing the image in the view controllers willAnimateToOrientation: method so that you can put the image changes inside UIKit's animation block.

iOS swipe filters over static image

I'm looking for a way to swipe image filters over top of a still image.
Mainly the base image stays in place, and the filters slide in over top when you swipe left or right.
Right now I have a base UIImageView and a Collection View over top of it which in theory would hold the filters (texture and gradient images).
I've read that UIImageViews and UIViews can't be live composited on top of each other, and that you must make the image before displaying it. So I can pre-make the image beforehand in code, then can I wipe-reveal the filter image to get the same effect? Using masks?
Code examples are nice, but a high level description on how to approach this would be helpful.
The app Spark has this functionality for videos, I'm looking to do something similar for photos.
So I can pre-make the image beforehand in code, then can I wipe-reveal the filter image to get the same effect? Using masks?
Yes, but no need for a mask. Pre-make the filtered image and put it in an image view. Let's say this filtered effect is to be swiped in from the left. Then make the image view's content mode be Left, and put it at the left of the real image, with width zero. As the swipe happens, animate the width of the image view to the width of the image. This will cause the filtered image to be revealed from the left side.

Resources