iOS 4.1 中的 NSCFNumber 类是什么?
在iOS 4.1上成功从iPhone相机获取图片后,您可以使用该密钥
@"UIImagePickerControllerMediaMetadata"
返回有关图片的信息。该字典中的键之一是
@"Orientation"
根据我的实验,肖像和颠倒分别是 6 和 8,风景是 1 和 3。看看这段代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSDictionary *metaData = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
id orientation = [metaData objectForKey:@"Orientation"];
NSLog(@"Class: %@",[orientation class]);
NSLog 说“Class:NSCFNumber”
我需要比较这个对象的值以确定如何进行。横向是 1 或 3,纵向是 6 或 8。我不确定要输入什么方向或在其上调用什么。 NSNumber 和 NSInteger 总是告诉我我正在从指针生成整数而不进行强制转换。
感谢您抽出时间!
After successfully acquiring a picture from the iPhone camera on iOS 4.1, you can use the key
@"UIImagePickerControllerMediaMetadata"
to return information about the picture. One of the keys in that dictionary is
@"Orientation"
From my experimentation, Portrait and Upside down are 6 and 8 respectively, and the landscapes are 1 and 3. Look at this code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSDictionary *metaData = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
id orientation = [metaData objectForKey:@"Orientation"];
NSLog(@"Class: %@",[orientation class]);
The NSLog says "Class: NSCFNumber"
I need to compare this object's value to determine how to proceed. Landscape is 1 or 3, portrait is 6 or 8. I'm not sure what to type orientation as or what to call on it. NSNumber and NSInteger always tells me I'm making integers from pointers without casts.
Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这告诉您方向是
NSNumber
的一个实例。从技术上讲,NSCFNumber
是NSNumber
的私有子类,但这是您不必担心的实现细节。要获取整数值,您可以调用This is telling you that orientation is a instance of
NSNumber
. Technically,NSCFNumber
is a private subclass ofNSNumber
, but that is an implementation detail which you don't have to worry about. To get the integer value you would callNSNumber
是一个类簇。NSCFNumber
是该集群中类的具体“私有”实现。只需像使用NSNumber
对象一样使用返回值即可。NSNumber
is a class cluster.NSCFNumber
is a concrete, "private" implementation of a class in that cluster. Just use the returned value like you would anNSNumber
object.如今(2022)该方法已更改名称,您需要将其转换为 NSNumber 才能使用它,如下所示:
如果您想在 OutputConsole 上打印它,则需要使用 %d 而不是 %@,例如:
Nowadays (2022) the method has changed the name, and you needed to cast it to NSNumber before you can use it, like this:
And if you want to print it on OutputConsole, you need to use %d instead of %@, e.g.: