在运行时检查iOS版本? [英] Check iOS version at runtime?

查看:87
本文介绍了在运行时检查iOS版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我最后一个问题的后续。我使用 beginAnimations:context:来设置一个动画块来动画化一些UITextLabels。但是我在文档中注意到:在iOS 4.0及更高版本中不鼓励使用这种方法,而应该使用基于块的动画方法。



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

解决方案

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



您可以执行以下操作:

  if([[UIView class] respondingToSelector:@selector(animateWithDuration:animations:)]){ 
//使用块生成动画
}
else {
//动画旧方式
}
pre>

This is sort of a follow on from my last question. I am using beginAnimations:context: to setup an animation block to animate some UITextLabels. However I noticed in the docs that is says: "Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods instead."

My question is I would love to use animateWithDuration:animations: (available in iOS 4.0 and later) but do not want to exclude folks using iOS 3.0. Is there a way to check to iOS version of a device at runtime so that I can make a decision as to which statement to use?

解决方案

In many cases you do not need to check iOS version directly, instead of that you can check whether particular method is present in runtime or not.

In your case you can do the following:

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

这篇关于在运行时检查iOS版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆