【问题标题】:My dispatch animation doesn't works like i want to? iOS我的调度动画不像我想要的那样工作? iOS
【发布时间】:2014-02-01 21:33:35
【问题描述】:

我想制作一个动画,就像 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.
}

【问题讨论】:

    标签: ios facebook animation uiview dispatch


    【解决方案1】:

    尝试调用[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,因为它在动画方法上有一个延迟参数。

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多