-rw-r--r-- 1.0K Jul 9, 2015 · E4EC750 · ~1 min

How to Disable the Swipe Back Gesture in iOS 8

objective-c ios шпаргалки

iOS has a system gesture - swipe from the left edge of the screen and you go back to the previous screen. It's cool and intuitive, and it annoys me when apps disable it, but sometimes you still have to do it. For example, because of an interface decision that conflicts with this swipe.

So for iOS 8, add this to the current UIViewController:

in YouViewController.h:

// add the gesture handling protocol
@interface YouViewController : UIViewController <UIGestureRecognizerDelegate>

in YouViewController.m:

- (void)viewDidLoad {
  [super viewDidLoad];

  self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  self.navigationController.interactivePopGestureRecognizer.delegate = self;
}

#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
  // disable the gesture if this is swipe back
  if ([gestureRecognizer isEqual:self.navigationController.interactivePopGestureRecognizer]) {
    return NO;
  } else {
    return YES;
  }
}
[↵] open page kak-otklyuchit-zhest-swipe-back-v-ios-8.md
-rw-r--r-- 803B Jul 2, 2015 · 33C822E · ~1 min

Proper Date Parsing with RestKit. From NSString to NSDate

objective-c restkit шпаргалки

A problem came up because dates were being parsed incorrectly through RestKit - the time zone was not taken into account, so in the end all dates were displayed 3 hours later than they should have been.

Inside RestKit there are already several NSDateFormatters for parsing a date. If one fails, the second one is used, and so on. But none of them matched the format in which I was getting dates through the API. To parse dates correctly, you need to add your own NSDateFormatter, and put it first in the list so it is applied first:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss Z"];

[RKObjectMapping alloc];
[[RKValueTransformer defaultValueTransformer] insertValueTransformer:dateFormatter atIndex:0];
[↵] open page pravilnyj-parsing-dat-cherez-restkit-iz-nsstring-v-nsdate.md
-rw-r--r-- 2.3K Jun 8, 2015 · 994A146 · ~1 min

UIViewController Lifecycle

objective-c шпаргалки uiview

UIViewController Lifecycle

A small cheat sheet on the UIViewController lifecycle - which methods are called, and in what order, during different transitions between UIViewControllers.

[↵] open page zhiznennyj-tsikl-uiviewcontroller.md
-rw-r--r-- 870B Jun 2, 2015 · FD87417 · ~1 min

Transparent Image Viewer for OS X

os x objective-c полезное приложения

Transparent Image Viewer for OS X

I've been trying to come up with something that would make it convenient to do pixel-perfect screen layout while developing iOS apps. Something that would make it easy and visual to compare the mockup and the result. Today I hacked together this tool for OS X - an almost transparent window where you can open a mockup, place it over Xcode or the simulator, and see what you got. You can adjust the transparency with a slider to check how closely it matches.

Maybe it will be useful to someone. Or maybe someone else feels the same pain and will join the development.

The source code is on github.

Download the binary.

P.S. my first app for OS X.

[↵] open page transparent-image-viewer-dlya-os-x.md
-rw-r--r-- 1.4K Jun 1, 2015 · 676411C · ~1 min

CALayer+UIColor Category

objective-c xcode полезное шпаргалки

I found a nice little thing on Stack Overflow. In Xcode's Interface Builder you can set some UI values through User Defined Runtime Attributes. I needed to set a border. You can set the layer.borderWidth thickness and it will be picked up, but the color will not. layer.borderColor stores a value of type CGColorRef, while the color you can choose in Interface Builder is a UIColor. A simple category lets you use UIColor through the layer.borderUIColor property.

CALayer+UIColor.h :

//
// CALayer+UIColor.h
//
// Created by Sergey Armodin on 29/05/15.
// Copyright (c) 2015 Sergey Armodin. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>

@interface CALayer (UIColor)
/**
* CGColor to borderColor
*/
@property(nonatomic, assign) UIColor* borderUIColor;
@end

CALayer+UIColor.m :

//
// CALayer+UIColor.m
//
// Created by Sergey Armodin on 29/05/15.
// Copyright (c) 2015 Sergey Armodin. All rights reserved.
//

#import "CALayer+UIColor.h"

@implementation CALayer (UIColor)
/**
* Setter
*
* @param color UIColor
*/
- (void)setBorderUIColor:(UIColor *)color {
    self.borderColor = color.CGColor;
}

/**
* Getter
*
* @return UIColor
*/
- (UIColor *)borderUIColor {
    return [UIColor colorWithCGColor:self.borderColor];
}
@end

And voilà:

CALayer+UIColor Category

[↵] open page kategoriya-calayer-uicolor.md
-rw-r--r-- 976B May 25, 2015 · 656A140 · ~1 min

CompareShots

compareshots ios приложения

CompareShots

Released a new app - CompareShots.

While working, I had the thought that it would be nice to have some kind of tool for comparing the mockup and the actual result. I wrote this little tool in one evening. Then I spent a few more evenings making screenshots. Yeah, the screenshots took more time :)

The app lets you choose 2 images from the device library. For example, a designer's app or website mockup and a screenshot of what the developer built, and check whether it really matches pixel for pixel. While you keep your finger on the screen, the first image is shown. Take it away, and the second one appears. There is a transparency slider, so you can clearly see where things do not match. The mismatch result as an image can be shared, emailed, or sent to any other app that accepts images.

App for iPhone and iPad.

Download

[↵] open page compareshots.md
-rw-r--r-- 305B May 18, 2015 · D1006D5 · ~1 min

Thread-Safe Singleton Definition via GCD

objective-c шпаргалки

Cheat sheet. Tired of having to go hunt for it every time.

+ (instancetype)sharedInstance {
    static MyClass *sharedInstance = nil;
    static dispatch_once_t oncePredicate;
    dispatch_once(&oncePredicate, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
} 
[↵] open page potokobezopasnoe-opredelenie-singltona-cherez-gcd.md
makoni@arm1:~/blog$ cd ../page-15/ // ← previous cd ./page-17/ // more posts →