How to take screenshot of UIScrollView visible area?

前端 未结 8 1640
鱼传尺愫
鱼传尺愫 2021-02-13 16:57

How do I take a 1:1 screenshot of UIScrollView visible area? The content may be larger or smaller than UIScrollView bounds as well as half-hidden (I\'ve implemented custom scrol

8条回答
  •  你的背包
    2021-02-13 17:29

    @Abduliam Rehmanius's answer has poor performance, since if the UIScrollView contains a large content area, we will draw that entire content area (even outside the visible bounds). @Concuror's answer has the issue that it will also draw anything that is on top of the UIScrollView.

    My solution was to put the UIScrollView inside a UIView called containerView with the same bounds and then render containerView:

    containerView.renderInContext(context)
    

提交回复
热议问题