将RPSystemBroadcastPickerView添加到我的自定义视图并向其内部按钮发送事件时,UI无法响应

时间:2018-12-07 08:22:34

标签: ios iphone ios12 replaykit rpsystembroadcastpickerview

将RPSystemBroadcastPickerView添加到iOS 12上的自定义视图中并将触摸事件发送到其内部按钮时,UI被阻止,并且无法响应任何触摸事件。

这是我的代码: 收到通知时,我调用此方法来初始化我的自定义视图:

- (void)presentMyCustomView
{
    MyCustomView *myCustomView = [[[[UIApplication sharedApplication] delegate] window] viewWithTag:kMyCustomViewTag];
    if (!myCustomView)
    {
        myCustomView = [[MyCustomView alloc] init];
        myCustomView.tag = kMyCustomViewTag;
        [[[[UIApplication sharedApplication] delegate] window] addSubview:myCustomView];
        [myCustomView release];
    }
}

在MyCustomView类的init方法中,我创建RPSystemBroadcoatPickerView并将其添加到MyCustomView中:

RPSystemBroadcastPickerView *broadcastPicker = [[RPSystemBroadcastPickerView alloc] initWithFrame:CGRectMake(0, 0, 100.f, 100.f)];
broadcastPicker.preferredExtension = @"xxxxx";
self.broadcastPicker = broadcastPicker;
[self addSubview:broadcastPicker];
[broadcastPicker release];

但是,当我运行项目时,有时UI会阻塞并且MyCustomView上的所有其他元素都无法被触摸。 RPBroadcastPicker崩溃日志将在设备日志中找到,但每次常规崩溃日志都找不到。

我已经使用了许多方法,例如,直接将broadcastPicker添加到键窗口,但无济于事。

有人可以帮助我吗?非常感谢。

1 个答案:

答案 0 :(得分:1)

if (@available(iOS 12.0, *)) {
    RPSystemBroadcastPickerView *pickerView = [RPSystemBroadcastPickerView new];
    pickerView.preferredExtension = @"com.apple.sharescreen";
    SEL buttonPressed = NSSelectorFromString(@"buttonPressed:");
    if ([pickerView respondsToSelector:buttonPressed]) {
        [pickerView performSelector:buttonPressed withObject:nil];
    }
}