【问题标题】:#if for device detection in iPhone SDK#if 用于 iPhone SDK 中的设备检测
【发布时间】:2012-03-08 11:39:53
【问题描述】:

我很好奇为什么这段代码不起作用:

#if UI_USER_INTERFACE_IDIOM//() == UIUserInterfaceIdiomPad
@implementation UINavigationBar (Custom height)

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = CGSizeMake(self.frame.size.width,44+BreadCrumbBarHeight-1);
    return newSize;
}    

@end
#endif

有什么想法吗?

【问题讨论】:

标签: objective-c if-statement macros ios5


【解决方案1】:

UI_USER_INTERFACE_IDIOM() 是一个为运行时评估设计(和定义)的宏! 将其用于编译时评估将失败。

定义为:

#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)

调用 [UIDevice.. 将在编译时评估失败

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多