2

UIView の autoresizingMask プロパティに配列を提供することは可能ですか? これを行う理由は、ビューに追加する autoresizingMask プロパティを決定するいくつかの条件があるためです。

したがって、単に使用する代わりに:

self.view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;

私は次のようなことをしたい:

if (addMargin) {
   [items addObject:UIViewAutoresizingFlexibleRightMargin];
}
if (addWidth) {
   [items addObject:UIViewAutoresizingFlexibleWidth];
}

// Add to property
self.view.autoresizingMask = items;

なので、基本的にはこのプロパティの項目を条件付きで設定したいと思っています。

4

2 に答える 2

6

ちょっとしたマスクです。必要なものとビットごとにORするだけです。

if(addMargin)
    self.view.autoresizingMask |= UIViewAutoresizingFlexibleRightMargin;
if(addWidth)
    self.view.autoresizingMask |= UIViewAutoresizingFlexibleWidth;

マスクをリセットするには、マスクを 0 に設定します。特定の属性を削除する場合は、その属性を無効にして、マスクとビット単位の AND をとります。

if(removeMargin)
    self.view.autoresizingMask &= ~UIViewAutoresizingFlexibleRightMargin;
于 2011-08-18T17:23:26.073 に答える
2

自動サイズ変更は単なるマスクです。

UIViewAutoresizing resize = 0;
if (addMargin) {
    resize = resize | UIViewAutoresizingFlexibleRightMargin;
}
if (addWidth) {
    resize = resize | UIViewAutoresizingFlexibleWidth;
}

self.view.autoresizingMask = resize
于 2011-08-18T17:23:09.487 に答える