0

I have defined an UIImageView in my nib. After the app launches, I display an image in that UIImageView. Maybe I am on the wrong way, but what I want to do is the following:

The image which I load into the view is bigger than the view itself. I want that it is displayed in original size with hidden overlay. Then I want to slowly move that image inside that view in random directions.

Maybe you know html div containers with background images. there, you can set a position of that background image and change that position with JavaScript. I need something similar on iPhone.

Maybe an UIImageView is not the right thing for that? Or must I set the UIImageView to the full size of that image and then move the UIImageView around slowly? Could it be bigger than the iPhone's screen?

Thanks
  • 40,109
  • 71
  • 208
  • 322

2 Answers2

1

You need to crop the image. See Lounges' answer to this question.

Community
  • 1
  • 1
Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
1

This is the gist of my answer to pretty much the same question:

There isn't a simple class method to do this, but there is a function that you can use to get the desired results: CGImageCreateWithImageInRect(CGImageRef, CGRect) will help you out.

Here's a short example using it:

CGImageRef imageRef = CGImageCreateWithImageInRect([largeImage CGImage], cropRect);
[UIImageView setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
HitScan
  • 8,651
  • 3
  • 22
  • 17
  • i think for moving it, it would be bad to performance if cropping an big image 15 times a second. i just move the frame now, which has the size of the image. works fine for me :) but thanks, that cropping code may be useful too. – Thanks Apr 03 '09 at 13:52