I have an image that I'm using which is 960x1280. I have coordinates for a rectangle of x:391 y:772, x:574 y:772, x:574 y:870, x:391 y:870 which allows me to put the rectangle in the proper spot IF the image is still 960x1280. Of course, when I'm in Xcode, the screen size is 375x667.
When drawing the rectangle with the above coordinates, the rectangle is no longer visible. If just use the screen scale of 3 (UIScreen.main.scale) it's not accurate either.
I create a UIImageView that has constraints of 0 for all four sides and using aspect .fit or .fill. How do I now know the proper scale of the image so the rectangle is drawn in the right spot?
Thanks
Related
I have added an icon to my assets to be used in an image view. However, When I put it in an image view the outer edges seem to be larger than the image itself. Is there any way I can fully fill the image. Even when I try scale to fill or aspect fill, fit options still there remains a margin in between.
In other words I want my circular image to be tangent to the image view rectangle
The example of what I am trying to do
I have a view UIView that by default has a UIImageView (the blue square in the included image) that is centered in this main view (the gray square in the included image). The main view has an added CALayer that serves as a border (window or mask — the yellow rectangle in included image) through which the image can be seen. The user uses gesture recognizers to pan (translate), pinch (scale), and rotate the image view's transform, but I'd like to give them the option of transforming the image so it completely fills the yellow border (all four corners), much the same way the iOS crop tool does (see attached gif). I've tried to figure out how I can calculate the correct scale factor, but now I'm wondering — is there some simple formula or function that can help me solve this problem?
I want to thank anyone of you who is contributing to this community, and i which to find a solution to the issue that is presented below:
this is a capture of my xcode project Main Storyboard:
it contains a background image view with a grid picture and a small image view over it with a cercle picture.the content mode is the same for both views is aspect fit.
what i am trying to achieve here is to get the same combination between the two images, as in this picture, on all devices.
so basically sticking the cercle image to the background image (the grid image) so that if the background image dimensions change on another device the dimensions of the cercle image change the same way to keep the same view as in this picture.
I grabbed your image and clipped out the circle.
The "grid" actual pixels are 312 x 324. The "circle" is 30 x 30.
I set the grid imageView to fill, with a width-to-height ratio of 312:324 and a width of 0.75 to superview.
I set the circle imageView to fill, with a width-to-height ratio of 1:1 and a width constraint of 30:312 of the grid imageView.
Here is the result:
You would need to calculate the run-time" ratio for placement, but that's pretty straight-forward.
Edit:
I whipped up a simple example - has buttons to move the circle based on the intersection points: https://github.com/DonMag/GridScale
stretch image right and left side
centre arrow remain as it is
i tried with it but centre down arrow position is not properly set by me.
You can't do this with sliced images.
The area between the edges will stretch or repeat in order to fill the area. You can't also preserver the centre section of an image this way.
What you might be better doing is creating a custom drawn view using either CALayer or drawRect.
I am trying to make a transition like APP Tinder.
Detail:
In Screen One there is a Vertical Rectangular UIImaveView with contentMode = Aspect Fill, so it hides some portion of Image to adujust Aspect Ratio.
In Screen Two (Detail Screen) the same image after transition has to to be passed, but the ImageView in Second screen is Square One.
I want to make a Morphing kind of Transition in which User should think that the same ImageView from Screen One become square one in Second one without stretching the Image.So What should i do?
Currently i am trying to get Frame of UIImage that is in visible area of UIImageView so that I can do some Logical stuff to achieve this. but can anyone help me to Get the Frame of Visible Portion of UIImage.
EDIT
Please Find out the Attached Image for understanding
I think there's a little ambiguity in the question: a frame must be specified in a coordinate system. But I think you're looking for a rect relative to the original, unclipped image.
If that's right, then the rect can be computed as follows. Say the image is called image, and the image view is imageView. The size of the rect is the size of the image view:
imageView.bounds.size
And, since aspect fill will center the oversized dimension, it's origin is:
CGPointMake((image.size.width - imageView.bounds.size.width) / 2.0, 0.0);