Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Rashii Henry
Rashii Henry
16,433 Points

Drawing an imageView into another imageView with UIGraphicsBeginImageContextWithOptions(URGENT)

I'm simply just trying to create a way to add an image over another image.

Of course, I was successful using UIGraphicsBeginImageContextWithOptions and drawing in a rect. when using an UIImageView and drawing an UIImage over it.

However, the problem arises simply because I want to place the image over the other, depending on where the user touches the screen.

there isn't a drawInRect method for imageViews, it's only for UIImages.

So another problem arises here as well, because when it comes to placing the image where the user touches, UIImages do not have the center property.

It's easy to place the Image when it's assigned to an imageView. Because you can set the touch location to it's center property.

However, when using UIGraphicsBeginImageContextWithOptions and trying to drawInRect that UImageView into the other ImageView, there's a compiler error notifying me that drawInRect does not have an interface to declare draw in rect.

My question is to you guys, How can I create a custom drawInRect Method where I can draw UIImageViews into one another.

OR

How can I position an UIImage to overlay over an Imageview and then save it's contents Using UIGraphicsContext....etc

ALL suggestions are welcome.

2 Answers

Stone Preston
Stone Preston
42,016 Points

can you not just programatically create the imageView object at the specified location?

Rashii Henry
Rashii Henry
16,433 Points

for example,

one big box as a background.

one little box that will be positioned on the big box, according to where you drag it.

then just save the whole context and conserve the resolution for retina displays.

Rashii Henry
Rashii Henry
16,433 Points

Yes, I can create it at the specific location.

The problem arises when I'm trying to save the context of the image(which is the result of both images being merged) based on where the user touches the screen.

it doesn't save the correct position of the imageview or maybe not even save the overLayed image at all.