我已经对 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?:/)