我想将imageview放在动画的不同位置

时间:2011-04-23 08:37:17

标签: iphone objective-c

我正在尝试在不同的位置设置多个图像这是我的代码,任何人都可以帮我在不同的位置设置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];
   }

1 个答案:

答案 0 :(得分:1)

您要添加子视图太晚,无法为屏幕上显示的内容制作动画。在开始某个位置的动画之前添加它们,然后设置为目标位置的动画。