• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

複数の矩形の和を求めていくとき、初期値には CGRectNull を使うといい。

CGRect v = CGRectNull;
for ( UIView* w in self.subviews ) v = CGRectUnion( v, w.frame );

CGRectZero は大きさ0の領域を持ってしまうので使えない。

CGRectUnion( CGRectNull, CGRectMake( 10, 10, 10, 10 ) )ー>10,10-10,10

CGRectUnion( CGRectZero, CGRectMake( 10, 10, 10, 10 ) )ー>0,0-20,20

posted by Saturn Saturn on Tue 30 Nov 2010 at 09:36 with 0 comments

applicationDidEnterBackground の中から beginBackgroundTaskWithExpirationHandler を呼ぶと backgroundTimeRemaining は 600 秒にセットされる(ことが多い?)
これをすぎても実行していると、先のポストと同様に終了させられる。

デバッガで実行していると、GCD でバックグラウンドジョブを投入した場合はちゃんと終了させられてしまうのだが、performSelector でバックグラウンドジョブを投入した場合は、生き残ってしまう(backgroundTimeRemaining がマイナスになって動き続ける)ので、必ず Organizer の Console で確認。

ちなみに1秒毎にログを出力してスリープするような軽いジョブを投入したらタイムアウトでサスペンドに移行した。
また延々素数を計算するようなジョブを投入するとタイムアウトで Kill された。

posted by Saturn Saturn on Thu 25 Nov 2010 at 02:51 with 0 comments

アプリケーションがバックグラウンドに入ったときアプリケーションのbackgroundTimeRemaining プロパティで示される残り時間が 0 になる前に処理を終えなくてはならない。この値は最初 10 秒にセットされている(ことが多い?)
処理を終えないとこんな感じで終わらせられる。

Thu Nov 25 11:30:01 xxxxx-no-iPhone BT[4821] : Remain:0.683624 100000127 is prime

Thu Nov 25 11:30:02 xxxxx-no-iPhone SpringBoard[1557] : BT[4821] has active assertions beyond permitted time:
{(
<SBProcessAssertion: 0x94d5ca0> identifier: Suspending process: BT[4821] permittedBackgroundDuration: 10.000000 reason: suspend owner pid:1557 preventSuspend preventThrottleDownCPU preventThrottleDownUI
)}

Thu Nov 25 11:30:02 xxxxx-no-iPhone SpringBoard[1557] : Forcing crash report of BT[4821]...

Thu Nov 25 11:30:02 xxxxx-no-iPhone SpringBoard[1557] : Finished crash reporting.

Thu Nov 25 11:30:02 xxxxx-no-iPhone com.apple.launchd[1] (UIKitApplication:jp.co.xxxxx.BT[0xc343][4821]) : (UIKitApplication:jp.co.xxxxx.BT[0xc343]) Exited: Killed

Thu Nov 25 11:30:02 xxxxx-no-iPhone SpringBoard[1557] : Application 'BT' exited abnormally with signal 9: Killed

Thu Nov 25 11:30:02 xxxxx-no-iPhone ReportCrash[4830] : Saved crashreport to /var/mobile/Library/Logs/CrashReporter/BT_2010-11-25-113002_xxxxx-no-iPhone.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0

posted by Saturn Saturn on Thu 25 Nov 2010 at 02:45 with 0 comments

自分の view が表示される前に別のタブで回転されている可能性があるので、回転に対応する処理をプログラムで行う場合は viewWillAppear の中でも処理を行わなくてはならない。

ruby>>
@implementation SomeViewController

  • (BOOL)
    shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
    }

  • (void)
    AdjustHV {
    switch ( self.interfaceOrientation ) {
    case UIInterfaceOrientationPortrait:
    case UIInterfaceOrientationPortraitUpsideDown:
    oV1.frame = CGRectMake(
    0
    , 0
    , self.view.frame.size.width
    , self.view.frame.size.height / 2
    );
    oV2.frame = CGRectMake(
    0
    , self.view.frame.size.height / 2
    , self.view.frame.size.width
    , self.view.frame.size.height / 2
    );
    break;
    case UIInterfaceOrientationLandscapeLeft:
    case UIInterfaceOrientationLandscapeRight:
    oV1.frame = CGRectMake(
    0
    , 0
    , self.view.frame.size.width / 2
    , self.view.frame.size.height
    );
    oV2.frame = CGRectMake(
    self.view.frame.size.width / 2
    , 0
    , self.view.frame.size.width / 2
    , self.view.frame.size.height
    );
    break;
    }
    }

  • (void)
    viewWillAppear:(BOOL)p {
    [ super viewWillAppear:p ];
    [ self AdjustHV ];
    }

  • (void)
    willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)p
    duration:(NSTimeInterval)pDuration {
    [ super willAnimateRotationToInterfaceOrientation:p duration:pDuration ];
    [ self AdjustHV ];
    }
    @end
    <<--

posted by Saturn Saturn on Wed 17 Nov 2010 at 10:00 with 0 comments

UITabBarController の中で UINavigationController を使っていて、その中で pushViewController で遷移している時に、それ自身の Tab をタップすると、navigationController が rootViewController に戻ってしまう。
これを避けるには UITabBarController の delegate をつなぎ、その delegate の中で以下のように自分自身かどうかを判断して YES/NO を返すようにする。

11/22 加筆
moreNavigationController がある場合、more のタブを2回タップすると、selectedIndexが NSNotFound になってくる。その対処を加えた。

ruby>>
- (BOOL)
tabBarController:(UITabBarController*)pTBC
shouldSelectViewController:(UIViewController*)p {
return pTBC.selectedIndex < pTBC.viewControllers.count
? [ pTBC.viewControllers objectAtIndex:pTBC.selectedIndex ] != p
: YES
;
}
<<--

posted by Saturn Saturn on Wed 17 Nov 2010 at 06:37 with 0 comments

NSOperationQue は(当然のことながら)別スレッドで動くので
中の NSOperation からUIKit を扱うときは
performSelectorOnMainThread
を使用してやりたい処理をメインスレッドにスケジュールしてやる。

ruby>>
@interface Operation : NSOperation {
}
@end
@implementation Operation
- (void)
Sub {
NSLog( @"Sub:%@", [ NSThread currentThread ] );
// UIKit を使う処理
}

  • (void)
    main {
    NSLog( @"main:%@", [ NSThread currentThread ] );
    [ self performSelectorOnMainThread:@selector(Sub) withObject:nil waitUntilDone:NO ];
    }
    @end

{
NSOperationQueue* w = [ [ [ NSOperationQueue alloc ] init ] autorelease ];
[ w addOperation:[ [ Operation alloc ] init ] ];
}
<<--

posted by Saturn Saturn on Tue 16 Nov 2010 at 02:32 with 0 comments
info.plist の Localization native development region で 'Japan' を指定すると 'その他' に変わる。
posted by Saturn Saturn on Thu 11 Nov 2010 at 08:03 with 0 comments
Contents rssrss
Value Transformer
AES & Blowfish in swift (CBC)
OreOre.pem の作り方
JSON Chat Server Skelton in GoLang TLS Ver.
JSON Chat Server Skelton in GoLang
UITextView と、UITextField でキーボードが出た時の Notification の順番が違う
Making window which covers iPhone's Status Bar
UIImagePickerController の編集領域
UIView の tag property
UILocationManager
Services from s21g
MagicBag
MagicBagは、Cloudflare R2やS3互換ストレージをMacのFinderから扱えるファイル同期クライアントです。
アンテナショップめぐり
東京にある全国のアンテナショップ、イベント、特産品を地図や条件から探せるサービスです。
YOMU Web小説リーダー
YOMUは、Web小説の読み上げに特化したiPhoneアプリです。
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
jotter.meは、考えやアイデア、情報を書き留めるためのノートサービスです。