Ios MPVolumeView路线按钮显示不一致

Ios MPVolumeView路线按钮显示不一致,ios,objective-c,airplay,mpvolumeview,Ios,Objective C,Airplay,Mpvolumeview,我正在使用视频覆盖中的MPVolumeview来使用路由按钮并连接到airplay。我隐藏MPVolume的音量滑块。我试图调整覆盖的大小,使其仅在airplay可用时才包含route按钮的框架。以前我在MPVolumeView中的route按钮上使用观察者,如下所示: for (UIView *view in volumeButton.subviews) { if ([view isKindOfClass:[UIButton class]]) { airplayButt

我正在使用视频覆盖中的MPVolumeview来使用路由按钮并连接到airplay。我隐藏MPVolume的音量滑块。我试图调整覆盖的大小,使其仅在airplay可用时才包含route按钮的框架。以前我在MPVolumeView中的route按钮上使用观察者,如下所示:

for (UIView *view in volumeButton.subviews) {
    if ([view isKindOfClass:[UIButton class]]) {
        airplayButton = [view retain];
        [airplayButton addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:nil];
    }
}

然后我设置一个布尔属性来跟踪按钮是否可见。然而,最近我在iPhone6上发现,route按钮在视频中的显示并不一致。我回顾了MPVolumeView,发现有一个属性现在称为areWirelessRoutesAvailable,因此我仔细检查了代码,发现这个属性并不总是正确的。我正在将MPVolumeView设置为从NIB唤醒,并在布局子视图中检查MPVolumeView。是否有更好的方法来检查airplay的可用性?route按钮是否始终显示MPVolumeView有问题,还是我遗漏了什么?

您可以为MPVolumeView添加观察者WirelessRoutesAvailabledDidChangeNotification,并在收到通知时调整覆盖的大小

    - (void)viewWillAppear:(BOOL)animated {
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(handleWirelessRoutesDidChange:)
                                                   name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:nil];
    }

    - (void)viewWillDisappear:(BOOL)animated {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }

    - (void)handleWirelessRoutesDidChange:(NSNotification *)notification {
        NSLog(@"Wireless routes did change: %@", notification);
        // Resize the overlay
    }

您可以为MPVolumeViewWirelessRoutesAvailableDidChangeNotification添加观察者,并在收到通知时调整覆盖的大小

    - (void)viewWillAppear:(BOOL)animated {
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(handleWirelessRoutesDidChange:)
                                                   name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:nil];
    }

    - (void)viewWillDisappear:(BOOL)animated {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }

    - (void)handleWirelessRoutesDidChange:(NSNotification *)notification {
        NSLog(@"Wireless routes did change: %@", notification);
        // Resize the overlay
    }

同样的问题,iPad 2上的按钮非常稳定,但iPhone 6上的按钮并不总是显示。在此处找到了永久显示airplay按钮的窍门:同样的问题,iPad 2上的按钮非常稳定,但iPhone 6上的按钮并不总是显示。在此处找到了永久显示airplay按钮的窍门: