简体   繁体   English

为什么这个简单的动画无法在iOS 7上运行?

[英]Why is this simple animation not working on iOS 7?

In my project I have a simple animation, I just move a view from left to right. 在我的项目中,我有一个简单的动画,我只是从左到右移动一个视图。 This works fine in iOS 6, but when I run in iOS 7 it does not do anything. 这在iOS 6中运行良好,但是当我在iOS 7中运行它没有做任何事情。 Does someone know why? 有人知道为什么吗? If the animation is very simple how can I fix this for iOS 7? 如果动画非常简单,我该如何修复iOS 7? My code is: 我的代码是:

- (void) showAnimation
 {
    if (IS_IPAD())
    {
       [UIView animateWithDuration:50.0f 
                             delay:1
                           options:UIViewAnimationOptionRepeat
                        animations:^{
                                         ViewBOLIVIA.frame = CGRectMake(1024,0,  ViewBOLIVIA.frame.size.width, ViewBOLIVIA.frame.size.height);
                                    } completion:nil];
    }
    else
    {
        if (IS_IPHONE_5)
        {
            [UIView animateWithDuration:50.0f 
                                  delay:1 
                                options:UIViewAnimationOptionRepeat 
                              animations:^{
                                               ViewBOLIVIA.frame = CGRectMake(568,0,  ViewBOLIVIA.frame.size.width, ViewBOLIVIA.frame.size.height);
                                          } completion:nil];
        }
        else
        {
             [UIView animateWithDuration:50.0f 
                                   delay:1 
                                 options:UIViewAnimationOptionRepeat
                              animations:^{
                                               ViewBOLIVIA.frame = CGRectMake(480,0,  ViewBOLIVIA.frame.size.width, ViewBOLIVIA.frame.size.height);
                                          } completion:nil];
        }
    }
 }

I did update and Im using Xcode 5 and iOS 7 so any help guys, do you know how fix this? 我做了更新,我使用Xcode 5和iOS 7所以任何帮助人,你知道如何解决这个问题吗?

OK I think I resolved it. 好的,我想我已经解决了。 Before iOS 7 it was okay to have animations running in viewDidLoad with storyboards. 在iOS 7之前,可以在带有故事板的viewDidLoad中运行动画。 If you move your animation calls to - (void)viewDidAppear then they should start working again. 如果将动画调用移动到- (void)viewDidAppear那么它们应该再次开始工作。 So in your case you will want to call [self showAnimation]; 所以在你的情况下你会想要调用[self showAnimation]; in - (void)viewDidAppear . in - (void)viewDidAppear

- (void)viewDidAppear{
   [self showAnimation];
}

I found placing the code in this method works. 我发现在这个方法中放置代码是有效的。

-(void)viewDidAppear:(BOOL)animated {
    menuView.alpha = 0;
    topLabel.alpha = 0;
    [UIView animateWithDuration:1.5 animations:^{
       menuView.alpha = 1;
       topLabel.alpha = 1;
    }];
   [super viewDidAppear:animated];
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM