2011-04-23 57 views
1

我想在不同的位置设置多个图像这是我的代码任何人都可以帮助我在不同的位置设置imageview。我想将imageview放置在与动画不同的位置

- (void)viewDidLoad 
{ 

    [super viewDidLoad]; 

frameX = 45.0f; 

    frameY = 60.0f; 

    imagearr = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"King2.png"], 
       [UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"queen.png"], 
       [UIImage imageNamed:@"King.png"],nil]; 

} 
-(IBAction)hidebtn:(id)sender 
{ 

    [btn setHidden:TRUE]; 
    [self setCards]; 

} 

-(void)setCards 
{ 

CGFloat dx = self.view.frame.size.width/2; 

    CGFloat dy = self.view.frame.size.height/2; 


    [cards setAnimationImages:imagearr]; 

    CGRect frame = cards.frame; 
    frame.size.width = frameX; 
    frame.size.height = frameY; 
    [cards setFrame:frame]; 
    cards.animationRepeatCount = 1; 
    for (int i=0; i<5;i++) 
    { 

[UIView beginAnimations:@"Move" context:nil]; 

[UIView setAnimationDuration:0.3]; 

     switch (i) 
     { 
      - (void)viewDidLoad 
{ 

    [super viewDidLoad]; 
    frameX = 45.0f; 
    frameY = 60.0f; 

    imagearr = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"King2.png"], 
       [UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"queen.png"], 
       [UIImage imageNamed:@"King.png"],nil]; 

} 
-(IBAction)hidebtn:(id)sender 
{ 
    [btn setHidden:TRUE]; 
    [self setCards]; 
} 

-(void)setCards 
{ 
    CGFloat dx = self.view.frame.size.width/2; 
    CGFloat dy = self.view.frame.size.height/2; 


    [cards setAnimationImages:imagearr]; 

    CGRect frame = cards.frame; 
    frame.size.width = frameX; 
    frame.size.height = frameY; 
    [cards setFrame:frame]; 
    cards.animationRepeatCount = 1; 

    for (int i=0; i<5;i++) 
    { 

     [UIView beginAnimations:@"Move" context:nil]; 
     [UIView setAnimationDuration:0.3]; 
     switch (i) 
     { 
      case 0: 
       [cards setCenter:CGPointMake(dx, dy-120.0)]; 
       cards.transform = CGAffineTransformMakeRotation(0); 
       break; 
      default: 
       break; 
     } 
     [self.view addSubview:cards]; 
     [UIView commitAnimations]; 

    } 


        default: 
       break; 
     } 
     [self.view addSubview:cards]; 
     [UIView commitAnimations]; 

    } 
+0

多一点信息会很好,你到底想做什么? – Robin 2011-04-23 08:42:10

+0

我有一个数组与多个图像,我想绘制每个图像在不同的位置,就像我们为卡片游戏中的每个玩家分发卡片一样。所以我想在不同的地方绘制多张卡片图像。 – Anjan 2011-04-23 08:44:59

+0

你能告诉我们什么类型的卡? – 2011-04-23 08:48:43

回答

1

您正在添加子视图的时间太晚,您不能在屏幕上设置动画效果。在开始动画之前添加它们,然后动画到目标位置。

+0

扑克牌是UIImageview,btn是Roundrect butoon,两者都与其定义的变量连接,所有进程顺利完成,但现在看到的结束imageview(卡),没有正确的动画做。谢谢Tomasz的回复 – Anjan 2011-04-25 05:35:02

相关问题