Creating a UIImage from a rotated UIImageView

OK – at last I seem to have done it. Any comments on the correctness would be useful… needed a translate, a rotate, a scale and an offset from the drawing rect position to make it work. Code is here: CGAffineTransform transform = CGAffineTransformIdentity; transform = CGAffineTransformTranslate(transform, boundingRect.size.width/2, boundingRect.size.height/2); transform = CGAffineTransformRotate(transform, angle); transform = … Read more

iOS: what’s the fastest, most performant way to make a screenshot programmatically?

I’ve found a better method that uses the snapshot API whenever possible. I hope it helps. class func screenshot() -> UIImage { var imageSize = CGSize.zero let orientation = UIApplication.shared.statusBarOrientation if UIInterfaceOrientationIsPortrait(orientation) { imageSize = UIScreen.main.bounds.size } else { imageSize = CGSize(width: UIScreen.main.bounds.size.height, height: UIScreen.main.bounds.size.width) } UIGraphicsBeginImageContextWithOptions(imageSize, false, 0) for window in UIApplication.shared.windows { window.drawHierarchy(in: … Read more