这是我最后一个问题的后续部分.我用beginAnimations:context:来设置一个动画块来设置一些UITextLabel的动画.然而,我注意到,在文件中说:"Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods instead."

我的问题是我想使用animateWithDuration:animations:(在iOS 4.0及更高版本中提供),但不想排除使用iOS 3.0的人.有没有办法在运行时判断设备的iOS版本,以便决定使用哪种语句?

推荐答案

在许多情况下,您不需要直接判断iOS版本,而是可以判断运行时是否存在特定的方法.

在您的情况下,您可以执行以下操作:

if ([[UIView class] respondsToSelector:@selector(animateWithDuration:animations:)]){
// animate using blocks
}
else {
// animate the "old way"
}

Objective-c相关问答推荐

Objective C 中的 RSA 实现

iPhone SDK 网络连接检测

如何使用 UIStepper

如何创建圆形按钮?

'if not' 的 Objective-C 预处理器指令

Asihttprequest 61 错误

是否可以将 NSInteger 转换为 NSNumber?

NSFileManager 唯一的文件名

为什么我的 UIButton 的内部修饰事件没有被调用?

NSMutableDictionary 线程安全

在 Objective-C 中访问命令行参数

静态 NSString 使用与内联 NSString 常量

Objective-C:如何使用 BOOL 类型的参数调用 performSelector?

带有 AVPlayer 的多个视频

当单元格全屏时,为什么 UICollectionView 会记录错误?

Obj-C 中的多值枚举

具有高质量代码的开源 Objective-C 项目?

无法从其 DataSource 获取单元格

UITableViewCell 选中行的文字 colored颜色 变化

无法更改 UILabel 文本 colored颜色