我的调度动画不能像我想的那样工作? iOS版

时间:2014-02-01 21:33:35

标签: ios facebook animation uiview dispatch

我想制作一个类似于Facebook在其应用程序的早期版本中使用的动画,其中标题出现在中心,在1或2秒后它会上升几个像素,因此有一些空间可用于登录或什么,问题是动画不能像我想的那样工作,我留下我的代码,所以你可以看到什么错误....谢谢!

- (void)viewDidLoad
{

    self.view.backgroundColor = [UIColor colorWithRed:51/255.0f green:204/255.0f blue:102/255.0f alpha:1.0];
    self.LogoImageView.center = self.view.center;

    if ([[UIScreen mainScreen] bounds].size.height == 568)
    {
        //IPHONE 4 i

        self.LogoImageView.frame = CGRectMake(33, 156, 255, 255);

    }else
    {
        //IPHONE 3.5 i

         self.LogoImageView.frame = CGRectMake(33, 112, 255, 255);
    }

    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [UIView animateWithDuration:1.0 delay:.35 usingSpringWithDamping:.10 initialSpringVelocity:.50 options:UIViewAnimationOptionCurveEaseInOut animations:^{

            if ([[UIScreen mainScreen] bounds].size.height == 568)
            {
                //iphone 5 image

                self.LogoImageView.frame = CGRectMake(33, 48, 200 , 200);

            }else
            {
                self.LogoImageView.frame = CGRectMake(33, 48, 200, 200);
            }




        } completion:nil];
    });






    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

1 个答案:

答案 0 :(得分:0)

尝试在动画之前调用[super viewDidLoad] 。我怀疑在动画制作时LogoImageView尚未初始化。

我不知道你是否也注意到了,但你在动画中设置的框架对于两种屏幕尺寸看起来都是一样的

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.view.backgroundColor = [UIColor colorWithRed:51/255.0f green:204/255.0f blue:102/255.0f alpha:1.0];


    // You can remove this line since you're already setting
    // the origin position right after.
    //
    // self.LogoImageView.center = self.view.center;

    BOOL isFourInchesScreen = [[UIScreen mainScreen] bounds].size.height == 568;
    if (isFourInchesScreen) {

        // IPHONE 4 i
        //
        self.LogoImageView.frame = CGRectMake(33, 156, 255, 255);

    } else {

        // iPhone 3.5 i
        //
        self.LogoImageView.frame = CGRectMake(33, 112, 255, 255);
    }

    [UIView animateWithDuration:1.0 delay:2.35f usingSpringWithDamping:.10 initialSpringVelocity:.50 options:UIViewAnimationOptionCurveEaseInOut animations:^{

        self.LogoImageView.frame = CGRectMake(33, 48, 200, 200);

    } completion:nil];
}

您也可以删除dispatch_after,因为动画方法上有延迟参数。

希望有所帮助。