I have a UIView with a UIImageView as a subview. I modify the UIView with CGAffineTransformRotate and CGAffineTransformScale. The UIImageView subview also transforms with it automatically.
I want to replace the UIImage in the UIImageView subview with a new UIImage. When I do this, the image is the wrong size and rotation, because the original been scaled and rotated.
How do I replace the image subview and have it appear as the previous image did (same size/rotation/location)?
Take another UIImageView2 and put your previous image in it first. Then after you scale and modify the original image to a new one and want to see your original one, you can show the UIImageView2 image.
I found the bug, I was removing the original image and didn't know it.
imageView.image = nextImage;
Changing the image as above keeps the scale and rotation from the parent. No trickery involved.
Related
I use Path2.0. I have found that when I click the small picture in a message,there would be an animation to show the whole picture. How does it do that?
I would really appreciate help here. Thanks!
UiImageView is bascially a UIView, which you can apply animation on.
The use case you want to achieve combines:
a. a response to touch event, which you can use UITapGestureRecoginizer to attache a block of code
b. zoom the UIImageView into a proper size and position, you can use UIView's class method AnimiationWithDuration....
c. Ultimately, you want to change your UIImageView's frame property to a larger one. use CGRectMake to generate a new one. If you need to take the whole screen estate (like Path 2.0 does), you may need [UIApplication sharedApplication].window for this
I doubt they modify the original UIImageView; but a solution might be:
Copy the UIImageView (or UIImage)
Add it as a subview with the same exact frame as the original image
Apply a scale transform on the UIImageView (by using the CGAffineTransformMakeScale() function on a UIView's transform property (inside a UIView animation block)
Then instantiate the root window with a scaled version of the full image
Alternatively, you could instantiate the new subview with the full image, set it with the original UIImageView's frame, and then (using a UIView animation block), set it to the newer frame. To match their implementation exactly, I suggest a black subview (of the full UIImageView) with an alpha of 0.0 that you then animate at the same duration to an alpha of 1.0.
From what I understand an UIImageView can contain a UIImage. Using the UIImageView you can then rotate the UIImage.
This, I believe, is done by assigning the UIImage an image of some sort and then, somehow, assigning the UIImage to the UIImageView.
I believe that I have "set" an image directly to a UIImageView and now wish to spin this image pinwheel style.
Is this possible or do I need to re-write so that my image is associated with an UIImage which is then, in turn, associated with the UIImageView?
I currently am using CGAffineTransformMakeRotation to attempt this on the UIImageView and the rotation looks more like it is flipping end over end and round and round.
Thanks
First, a UIImageView is just a view that knows how do draw an image on screen. That is it.
If you want to animate the spinning of an image you can either:
create separate images and load the array of images into the UIImageView; or
load a single image and use Core Animation to rotate the image.
Applying just a transform on the view will change it but won't animate it. That is what Core Animation is for.
I want to take an image from the UIImagePickerController and put it on a UIImageView that can move based on touch. I'm not sure how to get the picture onto the UIImageView. I thought the UIImageView automatically resizes the picture, so I couldn't grab just the top half of the picture and put that on the UIImageView. Is there an easy way to do this? thanks!
Use CGImageCreateWithImageInRect to crop (take a segment of?) a picture. Put a UIImageView inside a UIScrollView to let the user scroll through (move based on touch) a large image.
if you want to move and zoom your picture in a view, you need to use a UIScrollView. See Apple's ScrollViewSuite example. If you simply want to position the picture within a UIImageView, set the contentMode of the UIImageView to the setting you want e.g. scale, top, left, etc. See the UIImageView documentation for all options.
I have a custom UIImageView class which I use to handle multi-touch events on the UIImageView. When the user touch begins, I want to increase the UIImageView's frame but keep the UIImage size fixed.
I tried changing the UIImageView's frame and then calling the drawInRect: method of UIImage to keep the UIImage's size fixed. But this is not working.
The contentMode for the UIImageView is set as ScaleAspectFit and as soon as I increase the frame size of the UIImageView, the UIImage size also increases (and is not affected by the drawInRect:)
Can someone please tell me how I can achieve this?
Thanks.
Adding more details
What I am trying to do is this
Place a UIImageView on the screen with the size same as the size of the image
When the user selects the image, anywhere he touches, the image edits as if the user is doing multi-touch with the image
If I increase the size of the imageview to detect touches any where, the image size also increases... Hope that makes things clearer!
Thanks
There may well be other ways to do it, but I think the UIImageView is doing what it's intended to do here.
What do you want the area of the view not covered by the image to look like? Be transparent? Have a solid colour?
Why do you want to do this? Is it to capture touch events from a wider area than that under the image itself?
If you have a good reason for needing to do this I would create a new view, probably just a plain UIView (with background set to transparent colour), and add the UIImageView to that. Make the plain view the one you resize.
I haven't specifically tried this, but I think it would work:
imageView.contentMode = UIViewContentModeCenter;
set a UIImageView.image property to a UIImage is unable add the image to the view,however if i set the imageview frame property,it works.can anyone tell me how it's happen?
and what will happen when i apply the UIImage instance method[drawInRect:] redraw the image frame which is larger than the view frame?i have tried but nothing happen,and what is this function doing actual?
Generally, how it works is, you add an Image to a UIImageView and then add the UIImageView to a UIView to display it on the screen. You can do this programmatically, or using Interface Builder. Optionally, you can create a CGRect (based on a frame, if you like), use this as the bounds for the UIImageView (or you can frame the UIView). There are several ways to do what you want to do.
It's hard to tell without seeing your code. It could be a number of things. You could be inserting the view with the image behind the currentView? You may not be retaining the UIImageView. We can't read minds here necessarily, (sometimes we do). But you'll need to be more helpful if you want a solid answer.
Or just take a look at this:
UIImageView Docs