【问题标题】:Format specifies type 'int' but the argument has type 'UIViewContentMode'格式指定类型“int”,但参数的类型为“UIViewContentMode”
【发布时间】:2013-12-08 22:18:37
【问题描述】:

我在 Xcode 中收到警告:

格式指定类型'int'但参数有类型 'UIViewContentMode'

我有一个方法用于调整UIImage 的大小,如下所示:

- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode
                                  bounds:(CGSize)bounds
                    interpolationQuality:(CGInterpolationQuality)quality {
    CGFloat horizontalRatio = bounds.width / self.size.width;
    CGFloat verticalRatio = bounds.height / self.size.height;
    CGFloat ratio;

    switch (contentMode) {
        case UIViewContentModeScaleAspectFill:
            ratio = MAX(horizontalRatio, verticalRatio);
            break;

        case UIViewContentModeScaleAspectFit:
            ratio = MIN(horizontalRatio, verticalRatio);
            break;

        default:
            [NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
    }
...

UIViewContentMode 似乎引用了一个整数,所以我不确定这个警告:

typedef NS_ENUM(NSInteger, UIViewContentMode) {
    UIViewContentModeScaleToFill,
    UIViewContentModeScaleAspectFit,      // contents scaled to fit with fixed aspect. remainder is transparent
    UIViewContentModeScaleAspectFill, ... 

我怎样才能摆脱这个似乎不正确的警告?异常中的NSLog 是否正确?

【问题讨论】:

    标签: ios objective-c ios6 uiview ios7


    【解决方案1】:

    您可以像这样将NSInteger UIViewContentMode 转换为int

    [NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", (int)contentMode];
    

    【讨论】:

    • 谢谢两位,我之前尝试使用 (NSInteger) 进行投射。
    猜你喜欢
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 2020-08-02
    • 2015-06-10
    • 2017-09-04
    • 1970-01-01
    • 2016-09-29
    • 2014-01-28
    相关资源
    最近更新 更多