当前位置:编程学习 > wap >>

使用beginAnimations的问题

我想在一个动画block中,让一个button移动两次,而且设置了setAnimationDuration:3
但是表现出来的效果是,button直接移动到第一个位置,然后用了3秒的时间,移动到了第二个位置

请问是什么原因阿??

                [UIView beginAnimations:@"move button2" context:nil];
[UIView setAnimationDuration:5];

button1.frame = CGRectMake(100, 0, 100, 100);
                button1.frame = CGRectMake(100, 100, 100, 100);

[UIView commitAnimations];

--------------------编程问答-------------------- 帮顶。

偶也正在学习iphone的编程 --------------------编程问答-------------------- 把第一个Frame设置在beginAnimations之前再试试? --------------------编程问答-------------------- --------------------编程问答-------------------- 在回调里再移动第二次试试 --------------------编程问答-------------------- --------------------编程问答-------------------- 这就算是俩动画了 应该在第一个动画结束后调用setAnimationDidStopSelector:方法,方法里添加第二次动画。另外,记得setDelegate = self哦 --------------------编程问答-------------------- 貌似楼主没怎么理解iphone的动画,
你设置两次frame, 系统是不知道每次绘制动画多少时间的,所以展示的可能和你想的不一样;

你应该每次设置frame用一个动画效果,你要的就有了。 --------------------编程问答-------------------- 楼上厉害! --------------------编程问答-------------------- - (id)init{
    self = [super init];
    if (self != nil) {
        [self.view setBackgroundColor:[UIColor greenColor]];
        
        button1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, 20, 50)];
        [self.view addSubview:button1];
        button1.backgroundColor = [UIColor redColor];
        button1.hidden = NO;
        
        [UIView beginAnimations:@"move button" context:nil];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animation2:)];
        [UIView setAnimationDuration:2];
        
        button1.frame = CGRectMake(100, 0, 100, 100);
//        button1.frame = CGRectMake(100, 100, 100, 100);
//button1.frame = CGRectMake(200, 100, 100, 100);
        
        [UIView commitAnimations];
    }
    return self;
}

-(void)animation2:(id)sender{
    [UIView beginAnimations:@"move button" context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animation3:)];
    [UIView setAnimationDuration:2];
    button1.frame = CGRectMake(100, 100, 100, 100);
    //button1.frame = CGRectMake(200, 100, 100, 100);
    
    [UIView commitAnimations];
}

-(void)animation3:(id)sender{
    [UIView beginAnimations:@"move button" context:nil];
    [UIView setAnimationDuration:2];
    button1.frame = CGRectMake(200, 100, 100, 100);
    
    [UIView commitAnimations];
} --------------------编程问答-------------------- 动一次是一次动画,弄两个动画就好了。。。电脑没那么聪明的。。。
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,