Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Guild benguild

View GitHub Profile
View CIImage+Blur.swift
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 Mar 4, 2022
Block for finding topmost `UIViewController` of frontmost normal-level `UIWindow`.
View topmostViewControllerForFrontmostNormalLevelWindow.m
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 Feb 8, 2019
Properly scaled QR Code generator class method for `UIImage` (lightweight, avoids anti-aliasing/blurring)
View UIImage+QRCode.h
//
// 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)