Skip to content

Instantly share code, notes, and snippets.

View nantekkotai's full-sized avatar
🤡

Nobuyuki OSAWA nantekkotai

🤡
View GitHub Profile
@nantekkotai
nantekkotai / gist:2234119
Created March 29, 2012 06:23
MapKitでなぜかうまくいかないパターン

viewDidLoad内にて

// 以下の方法で初期緯度経度と範囲を指定して
MKCoordinateRegion region = myMapView.region;
region.center.latitude = 139.759955;
region.center.longitude = 35.674799;
region.span.latitudeDelta = 0.005;
region.span.longitudeDelta = 0.005;

// これを実行するとなぜか

@nantekkotai
nantekkotai / gist:2235680
Created March 29, 2012 10:26
iOSのOrientation固定の方法

viewController内の以下メソッドを修正する。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // もとのはコメント化
    //return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    // 以下の設定だとポートレート固定になる
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@nantekkotai
nantekkotai / gist:2822233
Created May 29, 2012 02:49
間違ってgit pushしちゃったどうしよう〜

間違えてgit pushしちゃいました〜☆

まずそいつを殴りましょう。
次に、正しい位置までoriginを戻します。

例えば、masterの abcdefg123 の位置まで戻したかったらこうする。

$ git push -f origin abcdefg123:master
@nantekkotai
nantekkotai / gist:2835300
Created May 30, 2012 10:02
Objective-Cにおけるユニットテストツールのメモ

GHUnit

標準のテストツールより良いって、知らないおっさんが言っていた。
http://gabriel.github.com/gh-unit/

使い方など

(後日作成する)

参考URL

@nantekkotai
nantekkotai / gist:2840814
Created May 31, 2012 03:44
UIImageの画像サイズを変更する

UIButtonにしろ、そのままイメージを使うにしろ、画像サイズを変更したい時がある。
そんな時は以下のような感じで頑張ると変更できる。

- (UIImage*)imageByShrinkingWithSize:(UIImage *)img
{
    // 元画像から8px小さくするとするじゃない
    CGRect rect = CGRectMake(0, 0,
 img.size.width - 8,
@nantekkotai
nantekkotai / gist:2840844
Created May 31, 2012 03:54
UIViewでアニメーションを行う

UIViewを継承したものであればアニメーションを実行することができる。

// 適当な要素が透明になるとする
hoge.alpha = 1.0;

[UIView animateWithDuration:0.2f
                      delay:0.2f
 options:UIViewAnimationOptionCurveEaseOut
@nantekkotai
nantekkotai / gist:2841485
Created May 31, 2012 06:26
Objective-Cでタイマーを使う

JavaScriptでいうところのsetTimeoutが使える。

// 30秒後にtimeoutメソッドを実行する
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:30.0f
                                                  target:self
                                                selector:@selector(timeout:)
                                                userInfo:nil
                                                 repeats:NO];
@nantekkotai
nantekkotai / gist:2841538
Created May 31, 2012 06:48
Objective-Cで正規表現

以下サンプルコード。

NSString *originStr = @"abogado ga umai!";
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"umai"
                                                                        options:0
                                                                          error:nil];

// ここでは置換してみる
@nantekkotai
nantekkotai / gist:2841665
Created May 31, 2012 07:27
Objective-Cで非同期通信を行う

Objective-Cで非同期通信を行なってAPIを叩くなどする場合はどうやるのか。

初期化

まず2つ変数を用意する。

@implementation Hogeee {
    NSMutableData *hogeData;
    NSURLConnection connection;
}
@nantekkotai
nantekkotai / gist:2841743
Created May 31, 2012 07:55
[iOS]CoreLocationで現在位置を取得する

CoreLocationを使ってGPSやらなにやらで現在位置を特定する。

Frameworkの追加

まずプロジェクトにCoreLocation.frameworkを追加する。

使用するファイルにimport

ここではサンプルとしてDemoViewControllerというものがあるとして、そこで位置取得を行う。