博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Interaction with the camera or the photo library
阅读量:4941 次
发布时间:2019-06-11

本文共 1918 字,大约阅读时间需要 6 分钟。

As we said before, we need a delegate to deal with the user interaction with the camera or the photo library. In order to do that we have to conform to the UIImagePickerControllerDelegate protocol. Also, since we are going to present the camera (or the photo library) modally, we have to implement the UINavigationControllerDelegate protocol as well. Add both protocols to the AppViewController.h file:

1

@interface
 APPViewController
 
:
 UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

When the user clicks (touch up inside) the “Take Photo” button, we have to create an UIImagePickerController and set its delegate to our AppViewController class. Also, we have to specify which kind of image picker we want to show, the camera with UIImagePickerControllerSourceTypeCamera, or a photo library with UIImagePickerControllerSourceTypePhotoLibrary; in this case we select the Camera. Once the picker has been crated, we have to present it modally with the method presentViewController.

Write the following takePhoto acton method:

1

2

3

4

5

6

7

8

9

10

-
 
(IBAction
)takePhoto
:
(UIButton
 
*
)sender
 
{

   
 

    UIImagePickerController
 
*picker
 
=
 
[
[UIImagePickerController alloc
]
 init
];

    picker.delegate
 
=
 self;

    picker.allowsEditing
 
=
 
YES;

    picker.sourceType
 
=
 UIImagePickerControllerSourceTypeCamera;

   
 

   
 
[self presentViewController
:picker animated
:
YES
 completion
:
NULL
];

   
 

}

Finally, we do the same for the selectPhoto action method, but changing the sourceType to UIImagePickerControllerSourceTypePhotoLibrary.

1

2

3

4

5

6

7

8

9

10

11

-
 
(IBAction
)selectPhoto
:
(UIButton
 
*
)sender
 
{

   
 

    UIImagePickerController
 
*picker
 
=
 
[
[UIImagePickerController alloc
]
 init
];

    picker.delegate
 
=
 self;

    picker.allowsEditing
 
=
 
YES;

    picker.sourceType
 
=
 UIImagePickerControllerSourceTypePhotoLibrary;

   
 

   
 
[self presentViewController
:picker animated
:
YES
 completion
:
NULL
];


   
 

}

转载于:https://www.cnblogs.com/vonk/p/4296472.html

你可能感兴趣的文章
从持续交付看敏捷开发的自相似性(敏捷开发的心跳)
查看>>
从优先级排序看敏捷开发的自相似性
查看>>
flex4 SuperTabNavigator 添加关闭图片
查看>>
flex4自定义皮肤
查看>>
敏捷开发中的MoSCoW优先级排序方法
查看>>
敏捷开发中史诗故事与用户故事的颗粒度
查看>>
asp.net免费网站三剑客:WebMatrix + MojoPortal + SQLCE
查看>>
C#编码简单性之语义篇(如何编写简短的C#代码,随时更新)
查看>>
flex4 设置 圆角
查看>>
在Chrome+Visual Studio中调试asp.net程序很慢的问题(Firefox也有类似问题)
查看>>
处理导出到EXCEL时,身份证号码的问题:mso-number-format
查看>>
C#编码简单性之函数篇(如何编写简短的C#代码,随时更新)
查看>>
flex AS中TabNavigator子项后报超出索引 commitProperties解决
查看>>
你必须懂的Java对象引用
查看>>
《快速软件开发——有效控制与完成进度计划》
查看>>
CentOS 5.5 安装配置全攻略 (无线上网 更新源 显卡驱动 firefox3.6 flash插件 编译boost1.43.0 雅黑字体...
查看>>
ASP.NET MVC 3 Beta: Built-in support for charts(MVC3 Razor中使用图表的最佳方案)
查看>>
Java实现简单的计算器(原创)
查看>>
Java实现的日历(原创)
查看>>
sql server 2005学习笔记之触发器简介(一)
查看>>