在Objective-C中,我订阅UIWindowDidBecomeVisibleNotification
以了解某些视图是否超出了我当前的视图控制器,使用:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoStartedPlaying:)
name:UIWindowDidBecomeVisibleNotification
object:nil];
到目前为止,这么好。然后,在通知中,我可以检查对象是否不某些类(如_UIAlertControllerShimPresenterWindow
-alert views-或UITextEffectsWindow
-native sharing view-)。在Objective-C中,我这样做了:
- (void)videoStartedPlaying:(NSNotification *)notification
{
if (
<radio_is_playing>
&&
! [notification.object isKindOfClass:NSClassFromString(@"_UIAlertControllerShimPresenterWindow")] // Alert view
&&
! [notification.object isKindOfClass:NSClassFromString(@"UITextEffectsWindow") ] // Share
)
{
// Video, stop the radio stream
}
}
这允许我在从UIWebView
(用于呈现新闻)开始播放视频时停止播放声音(在本例中为HTTP无线电流)。我试图在Swift中做同样的事情,所以我订阅了通知:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoStartedPlaying:", name: UIWindowDidBecomeVisibleNotification, object: nil)
现在,收到通知时......
func videoStartedPlaying(notification: NSNotification) {
if <radio_is_playing> && !notification.object? is _UIAlertControllerShimPresenterWindow && !notification.object? is UITextEffectsWindow {
// Stop the radio stream
}
}
Xcode说Use of undeclared type '_UIAlertControllerShimPresenterWindow'
。同样的事情发生在UITextEffectsWindow
。
我认为我必须导入某些东西来检测这些类,但我应该导入什么?
有没有其他方法可以在没有桥接Objective-C的情况下做到这一点?我怎么能访问那个班级?
提前谢谢。