Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过CATransaction completion来结束CADisplayLink并不安全 #23

Open
sooYo opened this issue Aug 11, 2020 · 0 comments
Open

通过CATransaction completion来结束CADisplayLink并不安全 #23

sooYo opened this issue Aug 11, 2020 · 0 comments

Comments

@sooYo
Copy link

sooYo commented Aug 11, 2020

####问题####
应用启动后,创建root tabbar controller后,VHLNavigation.m: pushNeedDisplay不断空转

####原因####
启动后创建root tabbar controller的自控制器中,有控制器包含了循环动画,导致以下代码执行失败(不会执行)

[CATransaction setCompletionBlock:^{
        [displayLink invalidate];
        displayLink = nil;
        vhlPushDisplayCount = 0;
        [viewController setPushToCurrentVCFinished:YES];
    }];

循环动画导致了CATransaction completion不会执行,从而最终导致空转

####复现####
目标controller

@implementation DisplayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    _testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [self.view addSubview:_testView];
    
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.fromValue = @(1);
    animation.toValue  = @(0);
    animation.repeatCount = CGFLOAT_MAX;
    animation.duration = 0.25;
    [_testView.layer addAnimation:animation forKey:@"test"];
}

发起点击controller,“completed”不会打印

@implementation ViewController

- (IBAction)test:(id)sender {
    DisplayViewController *vc = [[DisplayViewController alloc] init];
    
    [CATransaction setCompletionBlock:^{
        NSLog(@"completed");
    }];
    [CATransaction setAnimationDuration:10];
    [CATransaction begin];
    [self.navigationController pushViewController:vc animated:YES];
    [CATransaction commit];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant