0

我已经对 AVPlayerViewController 进行了子类化,并且需要查看 UIButton 以显示视频。我使用videoBounds 属性来布局这个按钮,使用 ReactiveCocoa:

@weakify(self);
[RACObserve(self, videoBounds) subscribeNext:^(NSValue *rect) {
    @strongify(self);
    NSLog(@"self.view : %@", NSStringFromCGRect(self.view.frame));
    NSLog(@"videoBounds : %@", NSStringFromCGRect(rect));

    button.frame = self.videoBounds; // for example
}];

这在 iOS8 中有效,但从 iOS9 开始,该属性似乎不再返回正确的视频边界。

日志:

0 - start with portrait:
self.view :{{0, 0}, {375, 667}}
videoBounds :{{0, 180.09090909090909}, {375, 306.81818181818176}}

1 - after rotating to landscape:
self.view :{{0, 0}, {667, 375}}
videoBounds :{{-41.666666666666686, 146}, {458.33333333333343, 375}}

2 - rotate back to portrait:
self.view :{{0, 0}, {375, 667}}
videoBounds :{{146, 34.090909090909093}, {375, 306.81818181818176}}

当你改变方向时,正确的框架将永远丢失...... :'(

任何人都偶然发现了同样的错误,或者有人对此有解决方案(手动计算videoBounds?:/)

4

1 回答 1

0

我遇到了同样的问题并通过从视图中删除播放器视图然后重新添加来修复它。

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    timerLabelContainer.setNeedsDisplay()
    player.view.removeFromSuperview()
    playerContainer.addSubview(player.view)
}
于 2016-04-02T14:16:11.443 回答