我有一个图像视图,并在其上设置了其他图像视图并将它们放在不同的位置。我想在法师视图上应用FLIP ANIMATION。怎么办当if(i == 1)时,我的imageview被翻转了。 img1
是我的图像视图,我想识别它。我在imagearr中分配了52张图像
我的代码:
-(void)setCards
{
int k=0;
CGFloat dx = self.view.frame.size.width/2;
CGFloat dy = self.view.frame.size.height/2;
int cnt = [imagearr count];
for (int j=1; j<3; j++) // Number of cards
{
for (int i=1; i<5; i++) // Number of players
{
int rnd = (arc4random() % cnt)-1;
UIImage *img = [imagearr objectAtIndex:rnd];
UIImageView *img1 = [[UIImageView alloc] initWithImage:img];
CGRect frame = img1.frame;
frame.size.width = frameX;
frame.size.height = frameY;
[img1 setFrame:frame];
[img1 setTag:k+i];
[UIView beginAnimations:@"Move" context:nil];
[UIView setAnimationDuration:0.50];
if (i==1)
{
[img1 setCenter:CGPointMake(dx+100, dy+(j*15))];
}
if (i==2)
{
[img1 setCenter:CGPointMake(dx+(j*15), dy+60)];
}
if (i==3)
{
[img1 setCenter:CGPointMake(dx-130, dy-(j*15))];
}
if (i==4)
{
[img1 setCenter:CGPointMake(dx-(j*20), dy-95)];
}
[self.view addSubview:img1];
[UIView commitAnimations];
[img1 release];
}
k=k+10;
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
int t = [touch view].tag;
}
我仍然无法识别特定的imageview。请帮我解决这个问题。
最佳答案
我认为您应该看一下Apple示例项目GeekGameBoard。它实现了单人纸牌游戏,您将能够学习如何选择代表卡片的CALayer
s *,将其拖曳以及使其相互交互。
*从性能的角度来看,这比使用视图更容易,而且可能更好。
关于objective-c - 从多个 ImageView 中识别特定的 ImageView ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5854016/