Skip to content

Commit 3cfbd67

Browse files
author
qinhui
committed
Fix picture-in-picture issue
1 parent 03c2289 commit 3cfbd67

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

iOS/APIExample-SwiftUI/APIExample-SwiftUI/Examples/Advanced/PictureInPicture/CustomRender/CustomRenderExample.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct CustomRenderExample: View {
4949
VStack(spacing: 30) {
5050
PIPDisplayView(viewModel: pipViewModel)
5151
.frame(maxWidth: .infinity, maxHeight: 200)
52-
52+
5353
Button {
5454
pipViewModel.togglePiP()
5555
} label: {
@@ -78,7 +78,6 @@ struct CustomRenderExample: View {
7878
customRenderViewModel.cleanRtc()
7979
}
8080
.frame(maxWidth: .infinity, maxHeight: .infinity)
81-
.adaptiveBackground(Color.orange)
8281
}
8382
}
8483

iOS/APIExample-SwiftUI/APIExample-SwiftUI/Examples/Advanced/PictureInPicture/PIPCommon/PIPDisplayView.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,24 @@ extension PIPViewModel: AVPictureInPictureControllerDelegate {
100100
guard let vc = pictureInPictureController.contentSource?.activeVideoCallContentViewController, let pipSourceView = backgroundView.pipSourceView else { return }
101101

102102
vc.view.addSubview(pipSourceView)
103-
pipSourceView.frame = vc.view.bounds
103+
pipSourceView.translatesAutoresizingMaskIntoConstraints = false
104+
NSLayoutConstraint.activate([
105+
pipSourceView.leadingAnchor.constraint(equalTo: vc.view.leadingAnchor),
106+
pipSourceView.trailingAnchor.constraint(equalTo: vc.view.trailingAnchor),
107+
pipSourceView.topAnchor.constraint(equalTo: vc.view.topAnchor),
108+
pipSourceView.bottomAnchor.constraint(equalTo: vc.view.bottomAnchor)
109+
])
110+
vc.view.layoutIfNeeded()
104111
}
105112

106113
func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
107114
guard let pipSourceView = backgroundView.pipSourceView else { return }
108115

109116
pipSourceView.removeFromSuperview()
110117
backgroundView.addSubview(pipSourceView)
118+
pipSourceView.frame = backgroundView.bounds
119+
pipSourceView.setNeedsLayout()
120+
pipSourceView.layoutIfNeeded()
111121
}
112122
}
113123

iOS/APIExample-SwiftUI/APIExample-SwiftUI/Examples/Advanced/PictureInPicture/SDKRender/SDKRenderExample.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct SDKRenderMockContainerView: View {
1313

1414
var body: some View {
1515
HStack {
16-
localView.frame(maxWidth: 200)
16+
localView
1717
ForEach(viewModel.remoteRenderViews) { view in
1818
view
1919
}
@@ -77,7 +77,6 @@ struct SDKRenderExample: View {
7777
sdkRenderViewModel.cleanRtc()
7878
}
7979
.frame(maxWidth: .infinity, maxHeight: .infinity)
80-
.adaptiveBackground(Color.orange)
8180
}
8281
}
8382

0 commit comments

Comments
 (0)