I want the user to go on my app and take a screenshot of the app after pressing a button programmatically in Swift. I know that UIGraphicsGetImageFromCurrentImageContext()
takes a screenshot but I don't want a picture of the entire screen. I want a rectangle to pop up (sort of like a crop tool) and the user can drag and resize the rectangle to take a screenshot of only a certain part of the screen. I want the rectangle to go over a WKWebView
and crop a pic of the web view.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
The standard snapshot technique is
drawViewHierarchyInRect
. And to get portion of a image, you can useCGImageCreateWithImageInRect
.Thus, in Swift 2:
In Swift 3:
And to use it, you can do:
This is a previously asked question at How to capture UIView to UIImage without loss of quality on retina display but to expand in swift (2.3):
So you can either get an image from a view with
UIView.image(theView)
or by asking the view itselflet viewImage = self.view.image()
Do bear in mind though that this is rough and probably needs further looking at for thread safety etc....