AVPlayerLayer SetFrame without animation

I have AVPlayerLayera home screen and I want to add it to UITableViewCell(every time I go to ViewControllerusing UITableView).

This is how I create it:

avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:audioPlayer];
[NowPlayingManager setPlayerLayer:avPlayerLayer];
[avPlayerLayer setFrame:CGRectMake(0, 0, CGRectGetWidth(self.playerView.frame), CGRectGetHeight(self.playerView.frame))];

This is how I add it to UITableViewCell:

[CATransaction begin];
[CATransaction setAnimationDuration:0];
[CATransaction setDisableActions:YES];
[[NowPlayingManager getPlayerLayer] setFrame:cell.img.frame];
[CATransaction commit];

[[cell layer] addSublayer:[NowPlayingManager getPlayerLayer]];

Now, when I return to the main view, I use this code:

if (avPlayerLayer && [avPlayerLayer superlayer] != [self.playerView layer]) {

    [CATransaction begin];
    [CATransaction setAnimationDuration:0.0];
    [CATransaction setDisableActions: YES];
    [avPlayerLayer setFrame:CGRectMake(0, 0, CGRectGetWidth(self.playerView.frame), CGRectGetHeight(self.playerView.frame))];

    [CATransaction commit];

    [[self.playerView layer] addSublayer:avPlayerLayer];
}

And the problem is that when I returned from UITableViewthe main one ViewController, AVPlayerLayer setframewith animation.

Any idea how I can fix this?

+4
source share

Source: https://habr.com/ru/post/1524295/


All Articles