我想以两种方式为UIButton制作动画

时间:2012-10-12 12:58:09

标签: iphone objective-c ios xcode

我在我的控制器中添加了一个UIView,然后在该视图上添加了一个UIButton。 我可以水平地动画那个视图,所以随着那个视图我的按钮也移动了,因为它添加了那个视图,但我希望当用户触摸按钮(这是动画)时,按钮应该是动画的。立刻下来了。   应该执行此按钮的动画,而较旧的视图动画(按钮的超级视图)是动画。

我已经这样做但是,按钮正在向下动画,直到该视图的大动画无法启动,一旦按钮的超级视图的动画开始,它就不会执行它之前执行的动画(触摸时) )。

这是代码

tempRabbit = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 360, 360)];
        tempView=[[UIView alloc]initWithFrame:CGRectMake(900, 0, 1024, 500)];
        UIImageView *temp=[[UIImageView alloc]initWithFrame:CGRectMake(0, 200, 360, 360)];
        UIButton *tempBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        [tempBtn setFrame:CGRectMake(0, 0, 360, 360)];
        [tempBtn addTarget:self action:@selector(rabbitTaped1) forControlEvents:UIControlEventTouchUpInside];
        [tempBtn setTitle:@"Show View" forState:UIControlStateNormal];


    NSArray *animationArray=[[NSArray alloc]init];
    animationArray=[NSArray arrayWithObjects:
                    [UIImage imageNamed:@"rabbit1.png"],
                    [UIImage imageNamed:@"rabbit2.png"],
                    [UIImage imageNamed:@"rabbit3.png"],
                    [UIImage imageNamed:@"rabbit4.png"],
                    [UIImage imageNamed:@"rabbit5.png"],
                    [UIImage imageNamed:@"rabbit6.png"],
                    [UIImage imageNamed:@"rabbit7.png"],
                    [UIImage imageNamed:@"rabbit8.png"],
                    [UIImage imageNamed:@"rabbit9.png"],
                    [UIImage imageNamed:@"rabbit10.png"],
                    [UIImage imageNamed:@"rabbit11.png"],
                    [UIImage imageNamed:@"rabbit12.png"],
                    [UIImage imageNamed:@"rabbit13.png"], nil];

    temp.animationImages=animationArray;
    temp.animationDuration=2;
    temp.animationRepeatCount=0;
    [temp startAnimating];

    //[tempRabbit addSubview:temp];
    [tempRabbit addSubview:tempBtn];
    [tempView addSubview:tempRabbit];
    [self.view addSubview:tempView];

0 个答案:

没有答案