3

我正在尝试使用一些按钮和控制器为我的主视图从屏幕右侧进入屏幕设置动画。问题是它没有动画,它只是直接进入完成状态。

这是我的代码:

UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
options = [storyBoard instantiateViewControllerWithIdentifier:@"OptionsView"];
options.delegate = self;        
[self.view addSubview:options.view];
options.view.center = CGPointMake(floor(total_width+options.view.frame.size.width/2)+10, floor(total_height/2));

[UIView animateWithDuration:0.5
                      delay:0.0
                    options: UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2));
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }]; 

编辑

更奇怪的是,如果我把这个动画放在另一个动画的完成块中,那么这个可以工作,但不是新的。

    UIButton* boton = (UIButton*) sender;
    [UIView animateWithDuration:5.0
                          delay:0.0
                        options: UIViewAnimationOptionCurveLinear
                     animations:^{
                         boton.alpha = 0.0;

                         //Jumps directly to 0, animation doesn't work

                     } 
                     completion:^(BOOL finished){
                         [UIView animateWithDuration:0.5
                                               delay:0.0
                                             options: UIViewAnimationOptionCurveEaseInOut
                                          animations:^{
                                              options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2));

                                              //It works now, but it doesn't take 5 seconds to start, it starts right away

                                          } 
                                          completion:^(BOOL finished){
                                              NSLog(@"Done!");
                                          }]; 

                     }];
4

1 回答 1

3

调用之前的行animateWithDuration:...直接将 分配给center您正在制作动画的相同值。要么删除它,要么在center那里分配初始值。具有相同开始值和结束值的动画显然没有效果。

于 2012-07-04T16:34:42.557 回答