【发布时间】:2015-05-21 08:56:49
【问题描述】:
我有一个由 4 个UIImageViews A、A2、A3 和 A4 组成的数组。我希望他们被拖到另一个名为 answerA 的 imageView 上。每次我将其中一个拖到答案上时,它都应该将 answerA 上的图像更改为一个数字,该数字表明拖了多少。例如。如果我在 answerA 上拖动 A,则 answerA 图像将变为数字 1。如果我从数组中再拖动一个 A,它将变为数字 2。由于某种原因,我的数组遵循一种奇怪的模式。我拖动的第一个更改为数字 1,第二个不执行任何操作,第三个将更改为数字 2,第四个将其更改回数字 1。无论我以哪种顺序拖动它们,它始终是相同的模式.
这是我的 4 个 imageViews 数组
@property (strong, nonatomic) NSArray *letterA; //initialized in .h
self.letterA = @[A, A2, A3, A4];//initialized in .m
我的碰撞检查方法:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
int intersectionCount = 0;
for (UIImageView *letter in letterA) {
if (CGRectIntersectsRect(letter.frame ,answerA.frame)) {
letter.userInteractionEnabled = NO;
letter.hidden = YES;
intersectionCount++;
}
}
if (intersectionCount == 1) {
UIImage *Pic1 = [UIImage imageNamed:@"number1.png"];
[correctCounterA setImage:Pic1];
}
else if (intersectionCount == 2) {
UIImage *Pic2 = [UIImage imageNamed:@"number2.png"];
[correctCounterA setImage:Pic2];
}
else if (intersectionCount == 3) {
UIImage *Pic3 = [UIImage imageNamed:@"number3.png"];
[correctCounterA setImage:Pic3];
}
else if (intersectionCount == 4) {
UIImage *Pic4 = [UIImage imageNamed:@"number4.png"];
[correctCounterA setImage:Pic4];
}
注意:correctCounterA 是 answerA 顶部的一个小 imageView,因此只有那一小部分会将图像更改为数字。
【问题讨论】:
标签: ios objective-c arrays uiimageview