日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

iOS 6编程-使用Photo Library(照片库)和相机

發布時間:2025/6/17 62 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS 6编程-使用Photo Library(照片库)和相机 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

將照片庫和App集成,可直接訪問存儲在iPhone、iPad 中的任何圖像或拍攝新照片,并在App 中使用。

1. 為了使用 UIImagePickerController,需要將類聲明為遵守2個協議:UIImagePickerControllerDelegate和UINavigationControllerDelegate。

@interface NoteViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

2. 顯示圖像選擇器

下面是點擊設置按鈕后,需要調用的方法 – 顯示圖像選擇器,讓用戶選擇圖像。
- (IBAction)settingButton:(id)sender {
UIImagePickerController *imagePicker;
imagePicker = [[UIImagePickerController alloc] init];

imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
// [self presentModalViewController:imagePicker animated:YES];
}

上述注釋的代碼,在iOS 6? 中不贊成使用。

3. 顯示選定的圖像

在用戶選擇好圖像之后,為了對用戶選擇的圖像做出響應,還需要實現委托方法imagePickerController:didFinishPickingMediaWithInfo:,下面是具體的代碼:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[self dismissViewControllerAnimated:YES completion:nil];
//[self dismissModalViewControllerAnimated:YES];
self.backgroundImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}

實現在當前場景的UIImageView元素中顯示用戶選擇的圖像。上述注釋的代碼,在iOS 6? 中不贊成使用。





轉載于:https://www.cnblogs.com/tuncaysanli/archive/2012/10/17/2727946.html

總結

以上是生活随笔為你收集整理的iOS 6编程-使用Photo Library(照片库)和相机的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。