Skip to content

Instantly share code, notes, and snippets.

View d-ronnqvist's full-sized avatar

David Rönnqvist d-ronnqvist

View GitHub Profile
@d-ronnqvist
d-ronnqvist / TextHitTestingLabel.m
Last active December 19, 2015 03:29
The complete implementation of my answer to a StackOverflow question about how to hit test the actual text of a UILabel. http://stackoverflow.com/a/17379627/608157
//
// TextHitTestingLabel.m
// rotate
//
// Created by David Rönnqvist on 2013-06-29.
//
#import "TextHitTestingLabel.h"
#import <CoreText/CoreText.h>
@d-ronnqvist
d-ronnqvist / gist:6600444
Last active April 17, 2017 08:24
The purpose of this gist is to provide examples of many real life date computations This is uploaded as a gist so that it can be copy and pasted into either a OS X or iOS project. You can either take it all "[Cmd]+[A], [Cmd]+[C]" or just a small piece. The results are fairly well formattes as log output and I recommend that you run this code to …
// The purpose of this gist is to provide examples of many real life date computations
// This is uploaded as a gist so that it can be copy and pasted into either a OS X or
// iOS project. You can either take it all "[Cmd]+[A], [Cmd]+[C]" or just a small piece.
// The results are fairly well formattes as log output and I recommend that you run this
// code to see the actual results yourself. Change some of the values and see what happens.
#pragma mark - Setup
NSString *line = @"–––––––––––––––––––––––––––––––––––––––––––––––––––––––";
@d-ronnqvist
d-ronnqvist / VideoView.m
Created November 8, 2013 08:55
This is the source code behind the Mac Video Wall that I was trying to port to iOS in [this Stack Overflow question](http://stackoverflow.com/questions/19065816/ios-alternative-to-qtmovielayer-that-has-non-nil-contents)
//
// VideoView.m
// MacVideoWall
//
// Created by David Rönnqvist on 9/28/13.
// This is the source code behind the Mac Video Wall that I was trying to port to iOS in [this Stack Overflow question](http://stackoverflow.com/questions/19065816/ios-alternative-to-qtmovielayer-that-has-non-nil-contents)
//
#import "VideoView.h"
@d-ronnqvist
d-ronnqvist / Thoughts on removedOnCompletion in SparkRecordingCircle.md
Last active May 16, 2020 02:51
What I think is wrong with the Spark Recording Circle code and why

There was [a tweet][tweetSoto] a couple of days ago that resulted in a discussion/question about what it wrong with the usage of removedOnCompletion = NO in the [SparkRecordingCircle code][code] for that [Subjective-C post][post].

We all kept saying that the explanation doesn't fit in a tweet, so here is my rough explanation about the issues.

But, let me first say that I think that the Subjective-C articles are reallt cool and useful to learn from. This is trying to reason about the general usage of removedOnCompletion = NO, using that code as an example, since that was what was discussed on twitter.


The root problem, as [Nacho Soto pointed out][rootProblem], is that removedOnCompletion = NO in combination with fillMode = kCAFillModeForwards is almost always used when you are not updating the model layer. This means that after the animation has finished, what you see on screen is not reflected in the property of the layer. The biggest issue that this can cause is that all the

Keybase proof

I hereby claim:

  • I am d-ronnqvist on github.
  • I am ronnqvist (https://keybase.io/ronnqvist) on keybase.
  • I have a public key whose fingerprint is 710B 9F42 55FC B0E9 DB06 9C2A 563F 6E00 ACB3 4F92

To claim this, I am signing this object:

@d-ronnqvist
d-ronnqvist / re-enable delete action.markdown
Last active January 6, 2024 07:23
How to break (and re-enable) the native accessibility "delete" action for table views

If you've haven't seen it before, there is a cool accessibility feature in UITableView that allows the user to toggle between different actions. It's really very elegant and it's a powerful and convenient implementation for VoiceOver users on iOS. One could say that it's the VoiceOver version of the swipe-to-delete feature.

To try it out yourselves, open one of the built in apps like Mail or Notes and turn on VoiceOver. If you are afraid to accidentally delete some of your important notes or email, you can also create a new Master-Detail Application in Xcode and run it on your device. Navigate to one of the cells and use the "Rotor" (rotate with two fingers on the screen) to find the "Actions" item. Now you can swipe up and down do toggle between "Activate Item (default action)" and "Delete". If you now double tap, the cell gets deleted instead of selected.

image with actions

This is the default behavior and you get this accessibility out of the box with UITableView.

@d-ronnqvist
d-ronnqvist / synthesize-readonly-in-subclass.m
Created July 14, 2014 09:13
Synthesizing a read-only property in a subclass overrides custom accessor
@interface Foo : NSObject
// some read-only property ...
@property (nonatomic, copy, readonly) NSString *bar;
@end
@implementation Foo
// ... with a custom accessor
- (NSString *)bar
{
return @"Foo";

The UIView animation API results in different CAAnimations being added to the layer on iOS 7 and 8. Changing the bounds of a view like this:

[UIView animateWithDuration:0.3 
                 animations:^{
    self.myView.bounds = CGRectMake(0, 0, 100, 100); // was (0,0) (200, 200)
}];

will result in one animation for the bounds key path being added to the backing layer if you are running iOS 7:

@d-ronnqvist
d-ronnqvist / gist:89768210611e18417b6d
Created October 19, 2014 15:47
Swift alternative to class clusters?

I wanted to use enums, structs, and classes to create small, elegant objects for a basic chess game.

It started with the small squares in the chess board, and created the logic part in the main definition and an extension that is use for rendering

enum Row: Character {
    case A = "A"
    case B = "B"
    case C = "C"
    case D = "D"
@d-ronnqvist
d-ronnqvist / gist:a70e6a1623bc7da85f1d
Last active August 29, 2015 14:10
The formatting horrors you sometimes need to go through to fit Objective-C in a two column layout
- (NSURL *) writeImage:(NSImage *)image
withSceneDocumentURL:(NSURL *)documentURL
originalImageURL:(NSURL *)originalImageURL
{
if (!originalImageURL) {
// Let the default exporter write this image
return nil;
}
NSString *sceneFileName =
[documentURL lastPathComponent];