翻转卡后检查相同的图像(Objective-C)

时间:2013-01-29 14:34:21

标签: ios objective-c ipad cocoa nsimage

我有4张卡片,我可以翻转我的卡片,我想检查我的图像是否是相同的显示2张图像,如果它不是翻转,

请你给我一些教程或示例代码;

提前致谢!

编辑:

这是我的图片:

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];
}

2 个答案:

答案 0 :(得分:1)

您可以按 NAME或网址/路径比较图片 但是在objective-c中你还可以比较两个对象,By,

if ([object1 isEqual:object2])

取BOOL变量imgCompare = NO;并检查条件

if([Imgobject1 isEqual:ImgObject2])
  imgCompare=YES;
else
  imgCompare=NO;

最好Question of related discussion,还要检查This Link.

谢谢:)

答案 1 :(得分:0)

您可以使用...

检查图像是否相等
BOOL imagesAreTheSame = [image1 isEqual:image2];