0

i have subclassed an AVPlayerViewController and need to view a UIButton to show over the video. I use the videoBounds property to layout this button, using 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
}];

This has worked in iOS8, but since iOS9 it seems that this property doesn't return the correct bounds of the video anymore.

logs:

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}}

When you change orientation, the correct frame will be lost forever... :'(

Anyone stumbled onto the same bug, or does someone have a solution for this (calculate the videoBounds manually? :/)

dOM
  • 555
  • 5
  • 14
  • All bugs should be reported to Apple using https://bugreport.apple.com . It helps if you have a minimal example. Alternatively this may be an issue in ReactiveCocoa (I don't know anything about this project) in which case you need to report it to the maintainers. – Robotic Cat Sep 24 '15 at 14:24
  • @RoboticCat - I have reported it, thanks – dOM Sep 24 '15 at 14:39

1 Answers1

0

I ran into the same problem and fixed it by removing the player view from the view then re-adding it.

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    timerLabelContainer.setNeedsDisplay()
    player.view.removeFromSuperview()
    playerContainer.addSubview(player.view)
}