iOS:使用数组的 AutoresizingMask?

发布于 2024-11-30 10:21:41 字数 529 浏览 2 评论 0原文

是否可以为 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;

所以我基本上想有条件地设置此属性的项目。

Is it possible to provide an array to the autoresizingMask property of UIView? The reason I want to do this is that I have some conditions which determine which autoresizingMask properties I want to add to my my view.

So, instead of just using:

self.view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;

I want to do something like:

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

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

So I basically want to conditionally set the items of this property.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

飘逸的'云 2024-12-07 10:21:41

有点面具了。只需将其与您想要的进行按位或即可。

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

要重置掩码,您可以将其设置为 0,或者如果您想删除特定属性,您可以将其取反并与掩码进行按位与:

if(removeMargin)
    self.view.autoresizingMask &= ~UIViewAutoresizingFlexibleRightMargin;

It's a bit mask. Just bitwise-OR it with the one you want.

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

To reset the mask, you can set it to 0, or if you want to remove a particular attribute you can negate it and bitwise-AND the mask with it:

if(removeMargin)
    self.view.autoresizingMask &= ~UIViewAutoresizingFlexibleRightMargin;
酷到爆炸 2024-12-07 10:21:41

自动调整大小只是一个位掩码。

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

self.view.autoresizingMask = resize

Autoresizing is just a bit mask.

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

self.view.autoresizingMask = resize
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文