为什么更改选项卡,在ios应用程序中停止动画?

前端之家收集整理的这篇文章主要介绍了为什么更改选项卡,在ios应用程序中停止动画?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用中有多个标签.我有一个视图控制器有动画运行,
当我切换到另一个视图控制器,再次来看动画控制器,然后动画停止,

任何人都可以指导我工作我的Xcode甚至切换Iphone应用程序中的选项卡?

- (IBAction)btn:(id)sender {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSString *soundStatus = [defaults objectForKey:@"Sound_Swich"];
    //NSLog(@"soundstatus is %@ ",soundStatus);
    if([soundStatus isEqual:@"YES"])
    {
        [self soundEffect];
    }
    if ([btnpress isEqualToString:@"start"]) {

        btnpress= @"pause";

        int radius = 100;
        circle = [CAShapeLayer layer];

        circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0,2.0*radius,2.0*radius)
                                                 cornerRadius:radius].CGPath;

        circle.fillColor = [UIColor clearColor].CGColor;
        circle.strokeColor = [UIColor greenColor].CGColor;

        circle.lineWidth = 5;
        [imgview.layer addSublayer:circle];



        // Configure animation
         drawAnimation= [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        drawAnimation.duration            = 5.0; // "animate over 10 seconds or so.."
        drawAnimation.repeatCount         = 8.0;  // Animate only once..
        // Animate from no part of the stroke being drawn to the entire stroke being drawn
        drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
        drawAnimation.toValue   = [NSNumber numberWithFloat:1.0f];

        // Experiment with timing to get the appearence to look the way you want
        drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

        // Add the animation to the circle
        [circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
        timerWasStarted=YES;
        //totalSeconds = 120;
        totalSeconds = 10;
        twoMinTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
                                                       target:self
                                                     selector:@selector(timer)
                                                     userInfo:nil
                                                      repeats:YES];

       // NSLog(@"start %@",[NSDate date]);
    }// to pause animation and timer
    else if ([btnpress isEqualToString:@"pause"]){
        flag=1;
        btnpress=@"resume";
        pauseStart = [NSDate dateWithTimeIntervalSinceNow:0];
        prevIoUsFireDate = [twoMinTimer fireDate];
        [twoMinTimer setFireDate:[NSDate distantFuture]];
       // NSLog(@"pause %@",[NSDate date]);
        [self pauseLayer:circle];


    }// to resume animation and timer

    else if([btnpress isEqual:@"resume"]&&flag==1){
        btnpress= @"pause";
        float pauseTime = -1*[pauseStart timeIntervalSinceNow];
        [twoMinTimer setFireDate:[NSDate dateWithTimeInterval:pauseTime sinceDate:prevIoUsFireDate]];
        [self resumeLayer:circle];
    }

    - (void)pauseLayer:(CALayer *)layer
    {

        pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
        layer.speed = 0.0;
        layer.timeOffset = pausedTime;
        //NSLog(@"pauSEOffset %f",pausedTime);
    }

    - (void)resumeLayer:(CALayer *)layer
    {
       // NSLog(@"resume %@",[NSDate date]);

        CFTimeInterval pausedTime1 = [layer timeOffset];
        layer.speed = 1.0;
        layer.timeOffset = 0.0;
        layer.beginTime = 0.0;
        timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime1;
        layer.beginTime = timeSincePause;

        //NSLog(@"resume offset %f",[layer timeOffset]);
    }

解决方法

我需要回答的是
drawAnimation.removedOnCompletion=NO;
原文链接:https://www.f2er.com/iOS/330661.html

猜你在找的iOS相关文章