Reputation: 1770
I have view with RPSystemBroadcastPickerView
view. In documentation apple shows example with assigning frame to this view like so:
https://developer.apple.com/documentation/replaykit/rpsystembroadcastpickerview?language=objc
When set frame + constraints, works as expected:
picker = RPSystemBroadcastPickerView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
but if i do initialize RPSystemBroadcastPickerView
like this:
picker = RPSystemBroadcastPickerView()
subviews doesn't display properly.
Constraints for both cases:
picker.translatesAutoresizingMaskIntoConstraints = false
pickerViewContainerView.addSubview(picker)
picker.widthAnchor.constraint(equalTo: pickerViewContainerView.widthAnchor).isActive = true
picker.heightAnchor.constraint(equalTo: pickerViewContainerView.heightAnchor).isActive = true
picker.leadingAnchor.constraint(equalTo: pickerViewContainerView.leadingAnchor).isActive = true
picker.topAnchor.constraint(equalTo: pickerViewContainerView.topAnchor).isActive = true
Do i have to set initial frame for this view? Because usually if you create and position view using constraints you don't have to assign initial frame.
Can somebody explain this behavior please?
Thanks.
Upvotes: 0
Views: 405
Reputation: 1177
Yes, you have to set the initial frame. You can check the width and height when you instantiate without initial frame.
picker = RPSystemBroadcastPickerView()
print("Height : \(picker.frame.height)") // this will print as 0.0
print("Width : \(picker.frame.width)") // this will print as 0.0
Since, the picker view is of height and width 0.0 x 0.0, it is not visible and is not working
With the initial frame the width and height prints 50.0 x 50.0 and visible.
picker = RPSystemBroadcastPickerView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
print("Height : \(picker.frame.height)") // this will print as 50.0
print("Width : \(picker.frame.width)") // this will print as 50.0
That is why in the Apple Developer Documentation they suggested to use initial frame.
Upvotes: 1