Skip to content

Instantly share code, notes, and snippets.

View benguild's full-sized avatar

Ben Guild benguild

View GitHub Profile
private func cameraPreviewObfuscationImage(from image: CIImage, with blurRadius: CGFloat, at targetSize: CGSize) -> UIImage? {
var blurAdjustedTargetSize = targetSize
if targetSize.width > targetSize.height {
blurAdjustedTargetSize.height += blurRadius * 2
} else {
blurAdjustedTargetSize.width += blurRadius * 2
}
let croppedImage = image.cropped(to: AVMakeRect(aspectRatio: blurAdjustedTargetSize, insideRect: image.extent))
@benguild
benguild / topmostViewControllerForFrontmostNormalLevelWindow.m
Last active March 4, 2022 04:26
Block for finding topmost `UIViewController` of frontmost normal-level `UIWindow`.
UIViewController *(^topmostViewControllerForFrontmostNormalLevelWindow)(void) = ^UIViewController *{
// NOTE: Adapted from various stray answers here:
// https://stackoverflow.com/questions/6131205/iphone-how-to-find-topmost-view-controller/20515681
UIViewController *viewController;
for (UIWindow *window in UIApplication.sharedApplication.windows.reverseObjectEnumerator.allObjects) {
if (window.windowLevel == UIWindowLevelNormal) {
viewController = window.rootViewController;
break;
@benguild
benguild / UIImage+QRCode.h
Last active February 8, 2019 04:50
Properly scaled QR Code generator class method for `UIImage` (lightweight, avoids anti-aliasing/blurring)
//
// UIImage+QRCode.h
//
// Created by Ben Guild on 2017/09/17.
// Copyright © 2017年 Ben Guild. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIImage (QRCode)