Scale UIView custom size without AutoLayout effects

Question

How to create a UIView with a custom size and then scale up / down to fit the UIViewController subtype?

Use case

I am developing an application, focusing on showing a custom UIView on an external monitor connected to an iOS device. A custom view must be created to naturally match the external monitor. Let's say the external display has a resolution of 1920x1080. The UIView will be created to fit that size, and then automatic layout would do it. - well!

Typically, the application user cannot see the external monitor, so another important part of the application is the provision of an external monitor on the iOS device. Of course, this small window will not have the same resolution as the external display, and just creating a different view and sticking to it on the internal display will not give the same results due to AutoLayout.

purpose

I would like to know how to create another custom instance of the view programmatically in the same size as the external display (so the layout is identical), and then scale this view up / down to fill in the preview on the internal display. Again, it is important that the preview window on the internal display is identical to what is displayed on the external display. I understand that there may be some scaling artifacts - this is completely normal.

Application example

, , liveevent.software. , iPad. , , , , , .....

UIView , . UILabels.

"" . , , . , iOS, ( ).

+4
3

, snapshotView. , snapshotView , . , , currentView .

SnapshotView, , gpu, .

+2

, " ", , UIView? UIImage, UIImageView . , , UIImageView .

, , : .

+2

, UIView , CGAffineTransform, (, , )

CGAffineTransform is an accelerated operation with a GPU, so performance should be quite optimal.

The only thing to note ( as the documentation warns ) is that it cannot play well with Autolayout, because the property frameis considered invalid, you will only have borders and a center to control the view.

0
source

Source: https://habr.com/ru/post/1672696/


All Articles