iOS - Why is my UIImageView moving? - ios

Here is my function for which I draw a metronome image within my iOS program.
When I load it, the metronome image is loaded, but "flies" down from the top left of the screen to the desired position. This is not the behavior I wanted - I simply want the image to appear at the desired position. Could someone enlighten me why this happens, and how to fix it?
Many thanks in advance.
Pier.
- (void) drawMetronomeForBeat: (int) beatNumber withNumberOfBeats:(int) noBeats
{
// remove any previous instances first
if (metronomeImageView)
{
[metronomeImageView removeFromSuperview];
}
NSString * imageName = #"metronome";
NSString * noBeatsStr = [NSString stringWithFormat:#"%d", noBeats];
NSString * beatNumberStr = [NSString stringWithFormat:#"%d", beatNumber];
imageName = [imageName stringByAppendingString:noBeatsStr];
imageName = [imageName stringByAppendingString:#"b"];
imageName = [imageName stringByAppendingString:beatNumberStr];
UIImage* image = [UIImage imageNamed: imageName];
UIImageView * symbolImageView = [[UIImageView alloc] initWithImage:image];
[symbolImageView setFrame:CGRectMake(410.0f, 215.0f, symbolImageView.frame.size.width, symbolImageView.frame.size.height)];
metronomeImageView = symbolImageView;
[self.view addSubview:symbolImageView];
}

Replace this line
[symbolImageView setFrame:CGRectMake(410.0f, 215.0f, symbolImageView.frame.size.width, symbolImageView.frame.size.height)];
with
[symbolImageView setFrame:CGRectMake(410.0f, 215.0f, 22, 22)]; //Change 22, 22 according to size that you need.
The image view will become larger or smaller according to the size of "real image" you are displaying. So it will move some where so that imageview will stay center aligned.
EDIT:
I think you are setting different frame for symbolImageView.
Try this
symbolImageView.frame = metronomeImageView.frame;

I was using the Controller to display the images. I restructured my code so that the images are always "drawn" in the drawRect of the view code, like this..
- (void)drawRect:(CGRect)rect
{
if (metronomeImage)
{
[metronomeImage drawInRect:CGRectMake(410.0f, 215.0f, metronomeImage.size.width, metronomeImage.size.height)];
}
}
This works with no problems - note that I just used drawInRect and just UIImage instead of setFrame and UIImageView. I suppose I'll just follow the convention that anything graphical should be done in the view code, and not the controller.

Related

UIImageView image is stretching when i am using rounded corners.

I am using UITableViewCell as UITableView Header. I am using the below code to make rounded corners for UIImageView.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if(section==0){
static NSString *simpleTableIdentifier = #"ContactDetailsHeaderTableViewCell";
ContactDetailsHeaderTableViewCell *cell = (ContactDetailsHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"ContactDetailsHeaderTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
..................
.................
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
//rounded corners
cell.profilePicImgView.clipsToBounds = YES;
UIGraphicsBeginImageContextWithOptions(cell.profilePicImgView.bounds.size, NO, 1.0);
// Add a clip before drawing anything, in the shape of an rounded rect
[[UIBezierPath bezierPathWithRoundedRect:cell.profilePicImgView.bounds
cornerRadius:60.0] addClip];
// Draw your image
[img drawInRect:cell.profilePicImgView.bounds];
// Get the image, here setting the UIImageView image
cell.profilePicImgView.image = UIGraphicsGetImageFromCurrentImageContext();
// end drawing
UIGraphicsEndImageContext();
.............
.............
}
Below is the output
The image inside the UIImageView is stretching, if i am not using the rounded corners then the image is looking properly. I have tried lot of code sample from StackOverflow but none of them are working.
A problem in your code is that you use dequeueReusableCellWithIdentifier to dequeue headers. You should use dequeueReusableHeaderFooterViewWithIdentifier instead, and base your header views on the designated class UITableViewHeaderFooterView. They are separate classes and are recycled differently when you navigate the table view.
Issue is that your image is not perfectly round thats why it looks like stretched image.
The issue is in following line...
[[UIBezierPath bezierPathWithRoundedRect:cell.profilePicImgView.bounds
cornerRadius:60.0] addClip];
Here you are setting cornerRadius:, if you want image view in complete round shape then your need to set cornerRadius: to cell.profilePicImgView.bounds.height/2 or may be .width/2.
You can make round corner in another way as below...
cell.profilePicImgView.image = //set image here
//Make image view round shape
cell.profilePicImgView.layer.cornerRadius = cell.profilePicImgView.bounds.height/2
//clip the bounds of image view
cell.profilePicImgView.clipsToBounds = YES;
Is your UIImageView is of fixed size?
Please check it the same. If not given fixed size, then you need to give cornerRadius of your ImageView as cell.profilePicImgView.bounds.height/2.
Also try to give contentMode = AspectFill.
Why are you making image round? You should make imageview round and you're done. You not need to do anything with image!
to make image view round you need to set it'e corner radius like,
yourImageView.layer.cornerRadius = yourImageView.frame.size.height/2;
yourImageView.clipsToBounds = YES;
yourImageView.contentMode = UIViewContentModeScaleAspectFill
yourImageView.image = [UIImage imageNamed:#"yourImageHere"];
Make sure that your image view's height and width is equal I mean it must be square to get exact round.
Second thing your approach to create header is wrong! You are dequeuing tableview cell in viewForHeaderInSection. This is wrong! Instead of this take or create one view (as xib or you can add view in storyboard beneath the main view) or create view programmatically and add your image view in that view and return that view from viewForHeaderInSection.
use this for rounding corner the image by increasing and decreasing the value as i am using small image currently borderColor is white
-(UIImageView*)SetupLayoutsImg:(UIImageView*)img{
UIColor* borderColor=[UIColor colorWithRed:244.0/255.0f green:244.0/255.0f blue:244.0/255.0f alpha:1.0/1.0f];
int borderwidth=1.0f;
int bottomViewRadius=10.0f;
img.layer.cornerRadius = bottomViewRadius; // this value vary as per your desire
img.contentMode = UIViewContentModeScaleAspectFill
img.layer.borderWidth=borderwidth;
img.layer.borderColor=borderColor.CGColor;
img.clipsToBounds = YES;
return img;
}
-(UIButton*)SetupLayoutsButtons:(UIButton*)Btn{
UIColor* borderColor=[UIColor colorWithRed:244.0/255.0f green:244.0/255.0f blue:244.0/255.0f alpha:1.0/1.0f];
int borderwidth=1.0f;
int buttonRadius=25.0f;
Btn.layer.cornerRadius = buttonRadius; // this value vary as per your desire
Btn.layer.borderWidth=borderwidth;
Btn.layer.borderColor=borderColor.CGColor;
Btn.clipsToBounds = YES;
return Btn;
}
How to use it by just calling it in uitableView delegate viewForHeaderInSection i am using it in cellForRowAtIndexPath like this
tableCellinside.cateImage=[self SetupLayoutsImg:tableCellinside.cateImage];
cateImage is my UIImageView you can use it like this s
cell.profilePicImgView=[self SetupLayoutsImg:cell.profilePicImgView];
Figured out the issue, posting the answer so it may help others. Its not related to rounded corners code. The rounded corners code is working fine. In UIImagePickerController i have set allowsEditing = YES but in didFinishPickingMediaWithInfo i was using UIImagePickerControllerOriginalImage so later i changed it to UIImagePickerControllerEditedImage. Now its working fine. I am able to get the rounded corners image without any stretch.
-(void)capturePhoto{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
/* earlier i have used UIImagePickerControllerOriginalImage in the place of UIImagePickerControllerEditedImage so it was not working properly*/
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
............
............
[picker dismissViewControllerAnimated:YES completion:NULL];
}

iOS: EXC_BAD_ACCESS on UIImage:drawInRect with 2 Images

I know that there are lots of questions to this topic here at StackOverflow, and i tried out many hints and answers hopefully. But nothing helped in this very plain and easy case.
--
In an ARC-based Application I use a UIView subclass called SpeechBubbleView from Ray Wunderlich. It subclasses a UIView and was made to draw a speech bubble containing text like in an SMS-Message-App.
It uses two instances of an UIImage. In the drawRect-Method of the View the bubbles where drawn.
In the iPhone-Simulator everything works fine. But on the iPhone 5 running iOS 7.1 there occure always an EXC_BAD_ACCESS exception every time the second Image is drawn, regardless if the first image was drawn or not.
I will provide some Code:
#property (nonatomic, retain) UIImage* lefthandImage;
#property (nonatomic, retain) UIImage* righthandImage;
At the initWithFrame-Method both images where loaded from the supported files folder:
self.lefthandImage = [[UIImage imageNamed:#"BubbleLefthand"]
stretchableImageWithLeftCapWidth:20 topCapHeight:19];
self.righthandImage = [[UIImage imageNamed:#"BubbleRighthand"]
stretchableImageWithLeftCapWidth:20 topCapHeight:19];
In the drawRect-Method of the SpeechBubbleView the images are drawn:
- (void)drawRect:(CGRect)rect
{
[self.backgroundColor setFill];
UIRectFill(rect);
CGRect bubbleRect = CGRectInset(self.bounds, VertPadding, HorzPadding);
CGRect textRect;
textRect.origin.y = bubbleRect.origin.y + TextTopMargin;
textRect.size.width = bubbleRect.size.width - TextLeftMargin - TextRightMargin;
textRect.size.height = bubbleRect.size.height - TextTopMargin - TextBottomMargin;
if (_bubbleType == BubbleTypeLefthand)
{
[self.lefthandImage drawInRect:bubbleRect];
textRect.origin.x = bubbleRect.origin.x + TextLeftMargin;
}
else
{
[self.righthandImage drawInRect:bubbleRect];
textRect.origin.x = bubbleRect.origin.x + TextRightMargin;
}
[[UIColor blackColor] set];
NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
textStyle.lineBreakMode = NSLineBreakByWordWrapping;
textStyle.alignment = NSTextAlignmentLeft;
[_text drawInRect:textRect withAttributes:#{NSFontAttributeName:font, NSParagraphStyleAttributeName:textStyle}];
}
At the code line, where the "RightHandImage" will be drawn, every time the BAD_ACCESS-Exception is thrown. If i comment this line out, everything works fine. The left-Hand-Bubble will be drawn perfectly as a "bubble".
Also, if i comment out the line where the first Image (left-Hand-Bubble) is drawn, the second Image will throw this exception.
Even if there is now multithreading implemented yet, i tried out to encapsulate the draw-Methods in #synthesize(...){...} following some hints here at StackOverflow to similar questions, but it was no solution and the Exception is still thrown every time.
I know that there is no other class holding an instance of this image to enter in access-rights-issues.
Can anyone give me some hints what to do here and now? Thank you!
EDIT: UITableViewCell-Hint and creating really, own Image-Copies
Maybe it's good to know that each Instance of the SpeechBubbleView is drawn in an reused UITableViewCell. Therefor, i do not use the UIImage-Instances returned by UIImage:imageNamed anymore, but create really copies of each using the following Code:
UIImage* tmpImage = [UIImage imageNamed:#"BubbleLefthand"];
self.lefthandImage = [[UIImage imageWithCGImage:[tmpImage CGImage] ]
stretchableImageWithLeftCapWidth:20 topCapHeight:19];
tmpImage = [UIImage imageNamed:#"BubbleRighthand"];
self.righthandImage = [[UIImage imageWithCGImage:[tmpImage CGImage] ]
stretchableImageWithLeftCapWidth:20 topCapHeight:19];
And, towards Putz1103 Suggestion, i added nil-guards around the draw-Methods:
if (_bubbleType == BubbleTypeLefthand)
{
if(self.lefthandImage != nil) {
[self.lefthandImage drawInRect:bubbleRect];
}
textRect.origin.x = bubbleRect.origin.x + TextLeftMargin;
}
else
{
if(self.righthandImage != nil) {
[self.righthandImage drawInRect:bubbleRect];
}
textRect.origin.x = bubbleRect.origin.x + TextRightMargin;
}
It still crashes on the iPhone, it only works in the iPhone-Simulator.
EDIT 2: Something with the Rect to draw in
It has something to do with the Rect. If i change the bubbleRect to a Rect starting at 0/0 with a width and height of 10 Pixel each, the Exception is not thrown.
If i use larger sizes of the rect the Exception occurs. So it seems that the Area is protected for something else
Change your code in the middle to
if (_bubbleType == BubbleTypeLefthand)
{
if(self.lefthandImage != nil)
[self.lefthandImage drawInRect:bubbleRect];
textRect.origin.x = bubbleRect.origin.x + TextLeftMargin;
}
else
{
if(self.righthandImage != nil)
[self.righthandImage drawInRect:bubbleRect];
textRect.origin.x = bubbleRect.origin.x + TextRightMargin;
}
Then see if it still crashes. If it does not (it shouldn't) you know it's because the images failed to load for one reason or another. Make sure the file names you are loading are case correct to the ones you are including in your project in the "Build Phases" section of the project properties.

Customise printing with UIActivityViewController

I've been using UIPrintInteractionController to print images in my app and it's worked out fine, since I can customise the page so that it prints with the appropriate margins.
I'm attempting to make use of the UIActivityViewController to do the same, however I've come across a bit of a block - whenever I pass in a UIImage in the activityItems, the print activity becomes available, however when it prints there are no margins and I'm not sure how to customise it. I've attempted to use UIMarkupTextPrintFormatter, however it then prints the image out over two pages and it's oversized, so part of the image is cut off the page. UIPrintInteractionController seemed to resize it appropriately when I passed in the image in the form of an NSData object.
This is what I've attempted to pass in the activityItems:
NSString *markupText = [NSString stringWithFormat:#"<html><body><img src='%#'></body></html>",self.imgURL]; //imgURL is the url of the image on the internet
UIMarkupTextPrintFormatter *htmlPrintF = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:markupText];
htmlPrintF.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins
htmlPrintF.maximumContentWidth = 6 * 72.0;
Ideally I don't want to be passing in the image URL since it takes up time downloading an image when it's already been downloaded and displayed once, and is retained in a UIImage object. The code above gives me the appropriate margins but the image is not sized appropriately to fit on the page.
It would be easier to just go back to using UIPrintInteractionController and ditch the UIActivityViewController, however I would like to have everything in one place, in UIActivityViewController.
Any ideas on how to control margins / image size when using UIActivityViewController?
This might look like a workaround but it will definitely help.
You can use -viewPrintFormatter method of UIImageView if you have the image already downloaded. You will need to create a UIImageView before presenting UIActivityViewController.
You can adjust contentInsets and maximumContentWidth etc. as you proposed.
Below sample takes an image, creates an imageView for resizing purposes and using its printFormatter.
- (void)showActivityWithImage:(UIImage *)image
{
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
CGFloat aspectRatio = image.size.width / image.size.height;
CGFloat maxWidth = 6.0f * 72.0f;
// resize image with aspect ratio if bigger than print size
// you can use a smarter resize here considering maxHeight also
if (image.size.width > maxWidth)
{
CGFloat height = maxWidth / aspectRatio;
[imageview setFrame:CGRectMake(0.0f, 0.0f, maxWidth, height)];
}
UIViewPrintFormatter *printFormatter = [imageview viewPrintFormatter];
printFormatter.contentInsets = UIEdgeInsetsMake(72.0f, 72.0f, 72.0f, 72.0f);
printFormatter.maximumContentWidth = maxWidth;
// printFormatter is added only for print activity
// image is used by others such as 'save image', 'mail'
NSArray *activityItems = #[image, printFormatter];
// create and present activityViewController
UIActivityViewController *activityController;
activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityController
animated:YES
completion:nil];
}

What limitations of an iPad 4 should I take into account when working with an array of images to produce an animation?

Here is what I'm trying to do: I want to have an app that displays a full-screen image and have that image animate by sliding a UISlider. A changing slider value will sequence through images of an array creating an animation. This animation is a single character on a turn-table. The character looks as though he is rotating around the turn table as the slider changes value.
This project is a portfolio piece for a 3D artist. The artist gave me a sequence of 180 images of the character rendered at the full screen retina resolution. He also gave be an additional 180 images rendered at the non-retina full screen resolution. The idea is that when somebody is viewing his character from any angle on a retina iPad, they can toggle using a UISwitch between retina and non-retina display. The code posted below works fine on the simulator.
However when running this code on an iPad 4, it works for a bit, then I get a memory warning. Then it crashes. I'm assuming having that many images of that size being displayed as fast as somebody wants to move a slider is too much for the iPad 4 to handle.
I'm curious what limitations I should take into account when working with images like this. Is 180 images way too many? What is a reasonable amount? Is there a more efficient way of producing my desired result? Instead of resorting the guess-and-check method of how many images would not cause it to crash, I figured somebody might have some useful insight on my issue.
#implementation RBViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_imageDisplay.image = [UIImage imageNamed:#"HyperReal_0.png"];
_arrayRetina = [[NSMutableArray alloc] initWithCapacity:180];
_arrayNormal = [[NSMutableArray alloc] initWithCapacity:180];
for(int i = 0; i < 179; i++)
{
NSString *myImageString = [[NSString alloc] initWithFormat:#"HyperReal_%i.png", i];
UIImage *myImageGraphic = [UIImage imageNamed:myImageString];
[_arrayRetina addObject:myImageGraphic];
}
for(int i = 0; i < 179; i++)
{
NSString *myImageString = [[NSString alloc] initWithFormat:#"lameHyperReal_%i.png", i];
UIImage *myImageGraphic = [UIImage imageNamed:myImageString];
[_arrayNormal addObject:myImageGraphic];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)switchButton:(id)sender {
if (_switchOnForRetina.isOn == YES)
{
_imageDisplay.image = [_arrayRetina objectAtIndex:_sliderBar.value];
}
else
_imageDisplay.image = [_arrayNormal objectAtIndex:_sliderBar.value];
}
- (IBAction)changeSlider:(id)sender {
if (_switchOnForRetina.isOn == YES)
{
_imageDisplay.image = [_arrayRetina objectAtIndex:_sliderBar.value];
}
else
_imageDisplay.image = [_arrayNormal objectAtIndex:_sliderBar.value];
}
#end
Instead of loading all 180 images at once into an array, couldn't you instantiate the current image to be displayed during the slider's continuous UIContolEventValueChanged event?
Create the slider
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 155, 20)];
slider.continuous = YES;
slider.value = 0.0f;
slider.minimumValue = 0.0f;
slider.minimumValue = 179.0f;
[slider addTarget:self action:#selector(handleContinuousSlider:) forControlEvents:UIControlEventValueChanged];
Handle it's continuous change event
- (void)handleContinuousSlider:(UISlider *)slider {
//create a UIImage with file name that makes the current integer value of the slider
NSString *myImageString = [[NSString alloc] initWithFormat:#"HyperReal_%i.png", slider.value];
UIImage *myImageGraphic = [UIImage imageNamed:myImageString];
//I assume this is a UIImageView
[_imageDisplay setImage:myImageGraphic];
[myImageGraphic release];
}
Prebuffering memory cost is roughtly:
((2048*1536*4 + 1024*768*4)*180)/1024/1024/1024 = 2.63671875 giga bytes
Even if there some underground optimisation going on, your iPad dont have enough memory to safely run that program.
As a work around your crashes, dont preload all images and instead just load required one
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[ self changeSlider: nil ];
}
- (IBAction)changeSlider:(id)sender {
if (_switchOnForRetina.isOn == YES)
{
_imageDisplay.image = nil;
NSString* pResourcePath = [ [ NSBundle mainBundle ] pathForResource: [ NSString stringWithFormat: #"HyperReal_%i", ( int )_sliderBar.value ] ofType: #"png" ];
_imageDisplay.image = [ UIImage imageWithContentsOfFile: pResourcePath ];
}
else
{
_imageDisplay.image = nil;
NSString* pResourcePath = [ [ NSBundle mainBundle ] pathForResource: [ NSString stringWithFormat: #"lameHyperReal_%i", ( int )_sliderBar.value ] ofType: #"png" ];
_imageDisplay.image = [ UIImage imageWithContentsOfFile: pResourcePath ];
}
}
A better solution here would be to create 2 h264 movies from your images sequence
one in forward animation order, second in backward animation order
then play right movie depending on slider animation
Of course that's a lot more work.
Cheers
I'm not quite sure why you need to programmatically switch between Retina and non-Retina, as #2x handles that really well, but I'll assume there is a usage case I'm not familiar with and will leave it at that.
Regarding the memory usage, we're working on an app with similar functionality, and our solution was to populate an array with strings that refer to the image names (or file paths) of all the individual frames. In your case, you would store the reference myImageString rather than myImageGraphic.
Then when you drag your slider, you'd use something like this:
- (IBAction)changeSlider:(id)sender
{
if (_switchOnForRetina.isOn == YES)
_imageDisplay.image = [UIImage imageNamed:[_arrayRetina objectAtIndex:_sliderBar.value]];
else
_imageDisplay.image = [UIImage imageNamed:[_arrayNormal objectAtIndex:_sliderBar.value]];
}
One additional point, we use imageWithContentsOfFile due to lower memory usage as per this post, though imageNamed's caching may help in this case.
EDIT:
As mccrager pointed out, the above method only changes on touch up. Here's an example I'm using, though I'm using UIGestureRecognizer on a UIView to send a percent to the method rather than relying on a slider.
- (void)dragPosition:(float)myPercent
{
NSInteger index = (self.images.count - 1) * myPercent;
NSString *imageName = [self.images objectAtIndex:index];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:#"jpg"];
self.image = [UIImage imageWithContentsOfFile:imagePath];
}
Hope this helps!

check the same images after flip cards (objective-C)

I have 4 cards and I can flip my cards, I want to check if my images is the same show 2 images and if it's not back the flip,
would you please give me some tutorial or sample code;
Thanks in advance!
Edit:
Here is my images:
UIImage *img1 = [UIImage imageNamed:#"card_front.png"];
[self addCardAtX:90 y:120 andFrontImage:img1 andTag:1];
[self addCardAtX:230 y:120 andFrontImage:img1 andTag:1];
[self addCardAtX:90 y:340 andFrontImage:img1 andTag:1];
[self addCardAtX:230 y:340 andFrontImage:img1 andTag:1];
- (void)addCardAtX:(CGFloat)x y:(CGFloat)y andFrontImage:(UIImage *) img1 andTag:(int)tag
{
UIImage *img2= [UIImage imageNamed:#"card_back.png"];
CardView *cv = [[CardView alloc] initWithFrontImage:img1 backImage:img2];
CGRect f = cv.frame;
f.origin.x = x-(f.size.width/2.0);
f.origin.y = y-(f.size.height/2.0);
cv.frame = f;
[self.view addSubview:cv];
}
You can Compare image by its NAME or URL/Path
But in objective-c you can also compare two objects, By,
if ([object1 isEqual:object2])
take BOOL variable imgCompare=NO; and check condition
if([Imgobject1 isEqual:ImgObject2])
imgCompare=YES;
else
imgCompare=NO;
Here is best Question of related discussion and also check This Link.
Thanks :)
You can check if images are equal buy using...
BOOL imagesAreTheSame = [image1 isEqual:image2];

Resources