UIViewAnimationOptions を読み解く

blockをつかったUIViewのアニメーション時に指定できるUIViewAnimationOptionsは次のようになっている。

enum {
   UIViewAnimationOptionLayoutSubviews            = 1 <<  0,
   UIViewAnimationOptionAllowUserInteraction      = 1 <<  1,
   UIViewAnimationOptionBeginFromCurrentState     = 1 <<  2,
   UIViewAnimationOptionRepeat                    = 1 <<  3,
   UIViewAnimationOptionAutoreverse               = 1 <<  4,
   UIViewAnimationOptionOverrideInheritedDuration = 1 <<  5,
   UIViewAnimationOptionOverrideInheritedCurve    = 1 <<  6,
   UIViewAnimationOptionAllowAnimatedContent      = 1 <<  7,
   UIViewAnimationOptionShowHideTransitionViews   = 1 <<  8,
   
   UIViewAnimationOptionCurveEaseInOut            = 0 << 16,
   UIViewAnimationOptionCurveEaseIn               = 1 << 16,
   UIViewAnimationOptionCurveEaseOut              = 2 << 16,
   UIViewAnimationOptionCurveLinear               = 3 << 16,
   
   UIViewAnimationOptionTransitionNone            = 0 << 20,
   UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,
   UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,
   UIViewAnimationOptionTransitionCurlUp          = 3 << 20,
   UIViewAnimationOptionTransitionCurlDown        = 4 << 20,
};
typedef NSUInteger UIViewAnimationOptions;

最初はこれらがなんのことかわからなくて、同時に複数のオプションを指定するときどうするの?とか思ってたんだけど、多分わかったから間違い覚悟で書いておく。
UIViewAnimationOptionsは符号なし整数で、上記enum中のものそれぞれに値が割り振られている。上9つに関しては各値はビットシフト演算されているので、上から順番に1、2、4、8と2のべき乗で大きくなっていく。だもんで、加算してもどれとどれをたしたのか判別可能、つまりは複数オプション同時指定可能になっている。なるほどなー。

UIViewAnimationOptionCurveなんとか同士、UIViewAnimationOptionTransitionなんとか同士はどれかひとつしか指定できない、と。


実際に複数指定する場合の書き方は試してみたらいくつか可能で、次のようになる。

一番最初の書き方が無難かな。