iOS:使用数组的 AutoresizingMask?
是否可以为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点面具了。只需将其与您想要的进行按位或即可。
要重置掩码,您可以将其设置为 0,或者如果您想删除特定属性,您可以将其取反并与掩码进行按位与:
It's a bit mask. Just bitwise-OR it with the one you want.
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:
自动调整大小只是一个位掩码。
Autoresizing is just a bit mask.