繁体   English   中英

如果应用进入前台ios,则恢复动画应用

[英]resume animation app if app enter foreground ios

我有一个小问题,当我的应用程序进入后台时,动画会停止,并且当应用程序返回到前台时不会恢复。

我已经试过了:

@implementation startViewController

-(void)animation {

    UIImage*img1 = [UIImage imageNamed:@"wolk2.png"];
    image1 = [[UIImageView alloc]initWithImage:img1];
    image1.frame = CGRectMake(0, 0, 400, 200);

    UIImage*img2= [UIImage imageNamed:@"wolk1.png"];
    image2 = [[UIImageView alloc]initWithImage:img2];
    image2.frame = CGRectMake(0, 0, 220, 100);

    [self.imageView addSubview:image1];
    [self.imageView addSubview:image2];
    [[self imageView]sendSubviewToBack:image1];
    [[self imageView]sendSubviewToBack:image2];



    CGFloat a = (CGFloat) (100);
    CGFloat b = (CGFloat) (100);
    CGFloat a1 = (CGFloat) (50);
    CGFloat b1 = (CGFloat) (350);
    CGPoint startPointOne=CGPointMake(a,b);
    CGPoint startPointTwo=CGPointMake(a1,b1);
    image1.center=startPointOne;
    image2.center=startPointTwo;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:20];
    [UIView setAnimationCurve: UIViewAnimationCurveLinear];
    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationRepeatCount:100000];

    CGFloat c = (CGFloat) (700);
    CGFloat d = (CGFloat) (100);
    CGPoint endPointOne=CGPointMake(c,d);
    image1.center = endPointOne;


    [UIView commitAnimations];

    [UIView beginAnimations:Nil context:NULL];
    [UIView setAnimationDuration:30];
    [UIView setAnimationCurve: UIViewAnimationCurveLinear];
    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationRepeatCount:100000];

    CGFloat c1 = (CGFloat) (650);
    CGFloat d1 = (CGFloat) (350);
    CGPoint endPointTwo=CGPointMake(c1,d1);
    image2.center = endPointTwo;
    [UIView commitAnimations];
}

然后在应用程序委托中输入以下内容:

 - (void)applicationDidBecomeActive:(UIApplication *)application
    {
 start = [[startViewController alloc]init];
        [start animation];

    }

但这没有用,那么我应该怎么做才能恢复动画?

您正在创建startViewController的新实例:

 - (void)applicationDidBecomeActive:(UIApplication *)application {
      start = [[startViewController alloc]init];
      [start animation];
 }

您应该调用startViewController的现有实例,它可能类似于:

- (void)applicationDidBecomeActive:(UIApplication *)application {
  [self.startViewController animation];
}

其中self.startViewController是一个属性,您可以在其中保留startViewController的实例。

暂无
暂无

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

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