ios – 恼人的警告:整数常量不在枚举类型的范围’UIViewAnimati
发布时间:2020-12-15 01:53:27 所属栏目:百科 来源:网络整理
导读:在XCode 5中编写如下代码时,使用clang设置为C11 / C 11: [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{ self.imgCheckIn.backgroundColor = [UIColor redColor]; } com
在XCode 5中编写如下代码时,使用clang设置为C11 / C 11:
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{ self.imgCheckIn.backgroundColor = [UIColor redColor]; } completion:nil]; 选项字段生成以下警告: integer constant not in range of enumerated type 'UIViewAnimationOptions' (aka 'enum UIViewAnimationOptions') [-Wassign-enum] 问题似乎是该方法采用UIViewAnimationOptions类型,它只是NSUInteger的枚举。然而,OR’ing值一起创建一个明确的枚举值,所以它抱怨。 一般来说,这似乎是一种很好的警告,所以我想保留它。我做错了吗? 解决方法
你没有做错什么正如你已经注意到的,编译器抱怨因为
值不是枚举中定义的值。 (编译器标志 – 这意味着这个检查。) 您可以通过显式转换来抑制警告: options:(UIViewAnimationOptions)(UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat) 或使用#pragma: #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wassign-enum" [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{ self.imgCheckIn.backgroundColor = [UIColor redColor]; } completion:nil]; #pragma clang diagnostic pop (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |