2011-04-23 55 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

相關問題