CoreLocationを使ってGPSやらなにやらで現在位置を特定する。
まずプロジェクトにCoreLocation.frameworkを追加する。
ここではサンプルとしてDemoViewControllerというものがあるとして、そこで位置取得を行う。
以下サンプルコード。
NSString *originStr = @"abogado ga umai!";
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"umai"
options:0
error:nil];
// ここでは置換してみる
JavaScriptでいうところのsetTimeoutが使える。
// 30秒後にtimeoutメソッドを実行する
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:30.0f
target:self
selector:@selector(timeout:)
userInfo:nil
repeats:NO];
UIViewを継承したものであればアニメーションを実行することができる。
// 適当な要素が透明になるとする
hoge.alpha = 1.0;
[UIView animateWithDuration:0.2f
delay:0.2f
options:UIViewAnimationOptionCurveEaseOut
UIButtonにしろ、そのままイメージを使うにしろ、画像サイズを変更したい時がある。
そんな時は以下のような感じで頑張ると変更できる。
- (UIImage*)imageByShrinkingWithSize:(UIImage *)img
{
// 元画像から8px小さくするとするじゃない
CGRect rect = CGRectMake(0, 0,
img.size.width - 8,
標準のテストツールより良いって、知らないおっさんが言っていた。
http://gabriel.github.com/gh-unit/
(後日作成する)
viewController内の以下メソッドを修正する。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// もとのはコメント化
//return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
// 以下の設定だとポートレート固定になる
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
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;
// これを実行するとなぜか