新聞中心
這里有您想知道的互聯網營銷解決方案
創(chuàng)新互聯IOS教程:iOS相機管理
iOS相機管理
相機簡介
相機是移動設備的共同特點之一,我們能夠使用相機拍攝圖片,并在應用程序里調用它,而且相機的使用很簡單。

在普陀等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網站設計、成都做網站 網站設計制作按需網站建設,公司網站建設,企業(yè)網站建設,成都品牌網站建設,營銷型網站建設,外貿營銷網站建設,普陀網站建設費用合理。
實例步驟
1、創(chuàng)建一個簡單的View based application
2、在ViewController.xib中添加一個button (按鈕),并為該按鈕創(chuàng)建IBAction
3、添加一個 image view (圖像視圖),并創(chuàng)建一個名為imageView的IBOutlet
4、ViewController.h文件代碼如下所示:
#import@interface ViewController : UIViewController { UIImagePickerController *imagePicker; IBOutlet UIImageView *imageView; } - (IBAction)showCamera:(id)sender; @end
5、修改ViewController.m,如下所示:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)showCamera:(id)sender {
imagePicker.allowsEditing = YES;
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else{
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (image == nil) {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
imageView.image = image;
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissModalViewControllerAnimated:YES];
}
@end
輸出
運行該應用程序并單擊顯示相機按鈕時,我們就會獲得下面的輸出
只要拍照之后,就可以通過移動和縮放對圖片進行編輯,如下所示。
網頁題目:創(chuàng)新互聯IOS教程:iOS相機管理
標題鏈接:http://www.dlmjj.cn/article/djsjgih.html


咨詢
建站咨詢
