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

如何暂停一个 UIView 中正在播放的动画?暂停后如何恢复? #151

Open
tbfungeek opened this issue Feb 19, 2020 · 0 comments

Comments

@tbfungeek
Copy link
Owner

tbfungeek commented Feb 19, 2020

- (void)idl_stopLayerAnimation {
    CFTimeInterval pauseTime =[self convertTime:CACurrentMediaTime() fromLayer:nil];
    self.speed = 0.0f;
    self.timeOffset = pauseTime;
}

- (void)idl_resumeLayerAnimation {
    CFTimeInterval pauseTime = self.timeOffset;
    self.speed = 1.0f;
    self.timeOffset = 0.0f;
    self.beginTime = 0;
    CFTimeInterval timeSince = [self convertTime:CACurrentMediaTime() fromLayer:nil] - pauseTime;
    self.beginTime = timeSince;
}

结合公式t = (tp - begin) * speed + offset就可以理解了

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