Skip to content

Instantly share code, notes, and snippets.

// This is more hacky than it should be!
- (UIModalPresentationStyle)pspdf_currentPresentationStyle {
UIViewController *vc = self.presentedViewController.presentingViewController;
if ([self respondsToSelector:@selector(adaptivePresentationStyleForTraitCollection:)]) {
UIModalPresentationStyle const style = [self adaptivePresentationStyleForTraitCollection:vc.traitCollection];
return (style == UIModalPresentationNone) ? self.presentationStyle : style;
}
// Before iOS 8.3 we have to fall back on assuming adaptivity is only possible for horizontally compact environments.
@douglashill
douglashill / UIImage+DHImageDecoding.m
Last active March 5, 2021 06:20 — forked from tonymillion/gist:6716935
Do not use this to decode an image without blocking the main thread, because it does block the main thread for non-obvious reasons.
@import ImageIO;
@implementation UIImage (DHImageDecoding)
/// Warning: do not use. This looks like it should work, but it blocks the main thread for non-obvious reasons.
+ (UIImage *)dh_decodedImageWithData:(NSData *)data
{
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
if (source == NULL) {
return nil;
@douglashill
douglashill / gist:6607468
Last active December 23, 2015 08:28 — forked from alistra/gist:5099553
NSStringFromCATransform3D
NSString * NSStringFromCATransform3D(CATransform3D t)
{
return [NSString stringWithFormat:@"CATransform3D {\n% 7.2f % 7.2f % 7.2f % 7.2f\n% 7.2f % 7.2f % 7.2f % 7.2f\n% 7.2f % 7.2f % 7.2f % 7.2f\n% 7.2f % 7.2f % 7.2f % 7.2f\n}", t.m11, t.m12, t.m13, t.m14, t.m21, t.m22, t.m23, t.m24, t.m31, t.m32, t.m33, t.m34, t.m41, t.m42, t.m43, t.m44];
}