• 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 Face Saturn on Tue 30 Nov 2010 at 09:33

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

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

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

posted by Face Saturn on Thu 25 Nov 2010 at 02:51

アプリケーションがバックグラウンドに入ったときアプリケーションの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: {( 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 Face Saturn on Thu 25 Nov 2010 at 02:45

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

   1  @implementation SomeViewController
   2  
   3  -	(BOOL)
   4  shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   5  	return YES;
   6  }
   7  
   8  -	(void)
   9  AdjustHV {
  10  	switch ( self.interfaceOrientation ) {
  11  	case UIInterfaceOrientationPortrait:
  12  	case UIInterfaceOrientationPortraitUpsideDown:
  13  		oV1.frame = CGRectMake(
  14  			0
  15  		,	0
  16  		,	self.view.frame.size.width
  17  		,	self.view.frame.size.height / 2
  18  		);
  19  		oV2.frame = CGRectMake(
  20  			0
  21  		,	self.view.frame.size.height / 2
  22  		,	self.view.frame.size.width
  23  		,	self.view.frame.size.height / 2
  24  		);
  25  		break;
  26  	case UIInterfaceOrientationLandscapeLeft:
  27  	case UIInterfaceOrientationLandscapeRight:
  28  		oV1.frame = CGRectMake(
  29  			0
  30  		,	0
  31  		,	self.view.frame.size.width / 2
  32  		,	self.view.frame.size.height
  33  		);
  34  		oV2.frame = CGRectMake(
  35  			self.view.frame.size.width / 2
  36  		,	0
  37  		,	self.view.frame.size.width / 2
  38  		,	self.view.frame.size.height
  39  		);
  40  		break;
  41  	}
  42  }
  43  
  44  -	(void)
  45  viewWillAppear:(BOOL)p {
  46  	[ super viewWillAppear:p ];
  47  	[ self AdjustHV ];
  48  }
  49  
  50  -	(void)
  51  willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)p
  52  duration:(NSTimeInterval)pDuration {
  53  	[ super willAnimateRotationToInterfaceOrientation:p duration:pDuration ];
  54  	[ self AdjustHV ];
  55  }
  56  @end

posted by Face Saturn on Wed 17 Nov 2010 at 09:56

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

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

   1  -	(BOOL)
   2  tabBarController:(UITabBarController*)pTBC
   3  shouldSelectViewController:(UIViewController*)p {
   4      return pTBC.selectedIndex < pTBC.viewControllers.count
   5  	?	[ pTBC.viewControllers objectAtIndex:pTBC.selectedIndex ] != p
   6  	:	YES
   7  	;
   8  }

posted by Face Saturn on Wed 17 Nov 2010 at 06:36

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

   1  @interface	Operation : NSOperation {
   2  }
   3  @end
   4  @implementation	Operation
   5  -	(void)
   6  Sub {
   7  NSLog( @"Sub:%@", [ NSThread currentThread ] );
   8      //  UIKit を使う処理
   9  }
  10  
  11  -	(void)
  12  main {
  13  NSLog( @"main:%@", [ NSThread currentThread ] );
  14  	[ self performSelectorOnMainThread:@selector(Sub) withObject:nil waitUntilDone:NO ];
  15  }
  16  @end
  17  
  18  
  19  {
  20  	NSOperationQueue*	w = [ [ [ NSOperationQueue alloc ] init ] autorelease ];
  21  	[ w addOperation:[ [ Operation alloc ] init ] ];
  22  }

posted by Face Saturn on Tue 16 Nov 2010 at 02:29

info.plist の Localization native development region で 'Japan' を指定すると 'その他' に変わる。

posted by Face Saturn on Thu 11 Nov 2010 at 07:58
Contents
CGRectNull,CGRectZero
beginBackgroundTaskWithExpirationHandler
applicationDidEnterBackground
TabBarController+NavigationController+multi orientation
tabBarController:shouldSelectViewController:
NSOperation が動くスレッド
TabBarController の More の言語
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ