iPhone 运营商

发布于 2024-09-17 01:33:55 字数 1818 浏览 8 评论 0原文

好的,我已经定义了我的 DSNavigationManager 类,它有一个名为 DSNavigationManagerStyle managerStyle 的属性:


typedef enum {
    DSNavigationManagerStyleNone                        = 0,
    DSNavigationManagerStyleDefaultNavigationBar        = 1 << 0,
    DSNavigationManagerStyleDefaultToolBar              = 1 << 1,
    DSNavigationManagerStyleDefault                     =
        DSNavigationManagerStyleDefaultNavigationBar + 
        DSNavigationManagerStyleDefaultToolBar,
    DSNavigationManagerStyleInteractiveNavigationBar    = 1 << 2,
    DSNavigationManagerStyleInteractiveToolBar          = 1 << 3,
    DSNavigationManagerStyleInteractiveWithDarkPanel    = 1 << 4,
    DSNavigationManagerStyleInteractiveWithBackButton   = 1 << 5,
    DSNavigationManagerStyleInteractiveWithTitleBar     = 1 << 6,
    DSNavigationManagerStyleInteractiveDefault          = 
        DSNavigationManagerStyleInteractiveNavigationBar + 
        DSNavigationManagerStyleInteractiveToolBar + 
        DSNavigationManagerStyleInteractiveWithDarkPanel + 
        DSNavigationManagerStyleInteractiveWithBackButton + 
        DSNavigationManagerStyleInteractiveWithTitleBar,
} DSNavigationManagerStyle;


我刚刚学会了如何使用按位移位,但我不知道如何接收此信息。我想做一些类似的事情:



DSNavigationManagerStyle managerStyle = DSNavigationManagerStyleDefault;

if(managerStyle "Has The DefaultNavigationBar bit or the DefaultToolBarBit") {
  // Implement
}
else {
    if(managerStyle "Has the InteractiveNavigationBar bit") {
        // Implement
    }
    if(managerStyle "Has the InteractiveToolBar bit") {
        // Implement
    }
    //.... and so on so that technically the object can implement all 
    //  styles, no styles, or any number of styles in between

}




Okay so I have defined my DSNavigationManager class and it has a property called DSNavigationManagerStyle managerStyle:


typedef enum {
    DSNavigationManagerStyleNone                        = 0,
    DSNavigationManagerStyleDefaultNavigationBar        = 1 << 0,
    DSNavigationManagerStyleDefaultToolBar              = 1 << 1,
    DSNavigationManagerStyleDefault                     =
        DSNavigationManagerStyleDefaultNavigationBar + 
        DSNavigationManagerStyleDefaultToolBar,
    DSNavigationManagerStyleInteractiveNavigationBar    = 1 << 2,
    DSNavigationManagerStyleInteractiveToolBar          = 1 << 3,
    DSNavigationManagerStyleInteractiveWithDarkPanel    = 1 << 4,
    DSNavigationManagerStyleInteractiveWithBackButton   = 1 << 5,
    DSNavigationManagerStyleInteractiveWithTitleBar     = 1 << 6,
    DSNavigationManagerStyleInteractiveDefault          = 
        DSNavigationManagerStyleInteractiveNavigationBar + 
        DSNavigationManagerStyleInteractiveToolBar + 
        DSNavigationManagerStyleInteractiveWithDarkPanel + 
        DSNavigationManagerStyleInteractiveWithBackButton + 
        DSNavigationManagerStyleInteractiveWithTitleBar,
} DSNavigationManagerStyle;


I just learned how to use bit-wise shifting but I don't know how to receive this information. I want to do something a little like:



DSNavigationManagerStyle managerStyle = DSNavigationManagerStyleDefault;

if(managerStyle "Has The DefaultNavigationBar bit or the DefaultToolBarBit") {
  // Implement
}
else {
    if(managerStyle "Has the InteractiveNavigationBar bit") {
        // Implement
    }
    if(managerStyle "Has the InteractiveToolBar bit") {
        // Implement
    }
    //.... and so on so that technically the object can implement all 
    //  styles, no styles, or any number of styles in between

}




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

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

发布评论

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

评论(2

記柔刀 2024-09-24 01:34:03

要检查特定位是否存在,请使用按位与 &(不要与逻辑与 && 混淆)。例如,

  01101101
& 00001000
----------
  00001000

如果您使用此值,它将被转换为布尔值,则任何非零值都被视为“true”,这使得这样的测试易于阅读:

if (managerStyle & DSNavigationManagerStyleDefaultToolBar) {
  ...
}

但是此测试不适用于您的复合值 - 对于例如,如果设置了位字段的任何组成位,则使用 DSNavigationManagerStyleDefault 处理位字段将返回“true”。

如果您确实想使用位域,请习惯所有按位运算符: http://developer.apple.com/tools/mpw-tools/commandref/appc_逻辑.html

To check for the presence of a particular bit, use the bitwise and, & (not to be confused with &&, the logical and). For example,

  01101101
& 00001000
----------
  00001000

If you use this value where it will be cast to boolean, any non-zero value is considered "true," which makes tests like this easy to read:

if (managerStyle & DSNavigationManagerStyleDefaultToolBar) {
  ...
}

But this test won't work well with your compound values - for example, anding a bitfield with DSNavigationManagerStyleDefault will return 'true' if any of its component bits are set.

If you really want to use bitfields, accustom yourself to all the bitwise operators: http://developer.apple.com/tools/mpw-tools/commandref/appc_logical.html

淡莣 2024-09-24 01:34:02
if (managerStyle & DSNavigationManagerStyleDefaultNavigationBar || managerStyle & DSNavigationManagerStyleDefaultToolBarBit) {
    // Implement
} else if (managerStyle & DSNavigationManagerStyleInteractiveNavigationBar) {
    // Implement
} else if (managerStyle & DSNavigationManagerStyleInteractiveToolBar) {
    // Implement
}
    //.... and so on so that technically the object can implement all 
    //  styles, no styles, or any number of styles in between
}

& 是按位 AND 运算符。您应该阅读有关按位运算的维基百科文章。

if (managerStyle & DSNavigationManagerStyleDefaultNavigationBar || managerStyle & DSNavigationManagerStyleDefaultToolBarBit) {
    // Implement
} else if (managerStyle & DSNavigationManagerStyleInteractiveNavigationBar) {
    // Implement
} else if (managerStyle & DSNavigationManagerStyleInteractiveToolBar) {
    // Implement
}
    //.... and so on so that technically the object can implement all 
    //  styles, no styles, or any number of styles in between
}

& is the bitwise AND operator. You should read the Wikipedia article on Bitwise operation.

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