How can a UIView be created with a user-defined size and then scaled up/down to fit as a subview of a UIViewController?
I am developing an application with a primary focus on showing a custom UIView on an external monitor attached to the iOS device. The custom view should be created to natively fit the external monitor. Let's say the external display has a resolution of 1920x1080. The UIView would be created to fit that size and then auto layout would do it's thing. - great!
Typically, the application user cannot actually see the external monitor, so another important part of the application is to provide a representation of the external monitor on the iOS device. Of course, these small window is not going to be the same resolution as the external display and simply creating another view and sticking it on the internal display is not going produce the same results because of AutoLayout.
I'd like to know how to create another custom view instance programmatically at the same dimensions as the external display (so the layout is identical) and then scale that view up/down to fill a subview on the internal display. Again, it is important that the preview window on the internal display is identical to what is being shown on the external display. I understand there may be some scaling artifacts - that is totally OK.
The application in question can be viewed at liveevent.software. My question is in reference to the the external display and the preview of the external display as viewed on the iPad screen. Of course, we have this working already, but we are adding more features and need the local preview to be exactly the same as the external to the operator knows if a message is too long etc...
The UIView being scaled does not contain any gesture recognizers or other items requiring user interaction. Just a few UILabels.
The current "working" solution is to create create two instances of the custom view and have them adapt according to auto-layout. While this produces a rough estimation of what is being displayed externally, it is not exact. For example, text may break a line on the iOS preview window but not on the actually external display (because it is larger dimensions).
Instead of creating another instance of the view and using resources to update both accordingly to user actions I would create a snapshot of the view at any change, by using snapshotView method. In terms of performances the snapshotView
is very efficient and returns a view object whose content is not editable. This means that you can scale it as you wish to have an exact mirror of your currentView on the second screen.
SnapshotView method probably uses gpu resources, leaving your CPU free to have an high frame rate and performances on your second screen.