淺談iPhone手機拍照功能和照片庫選取功能調用

來源:互聯網
上載者:User

淺談iPhone手機拍照功能和照片庫選取功能調用是本文要介紹的內容,內容不多,主要是以代碼實現,我們來看內容。

首先,你得實現UIImagePickerControllerDelegate,UINavigationControllerDelegate兩個代理

其次定義按鈕:

 
  1. // 從相簿裡上傳一張  
  2. UIButton *btn1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];  
  3. btn1.frame = CGRectMake(60.0, 237.0, 200.0, 32.0);  
  4. [btn1 setTitle:@"從媒體庫中選取圖片" forState:UIControlStateNormal];  
  5. [btn1 addTarget:self action:@selector(picker) forControlEvents:UIControlEventTouchUpInside];  
  6. UIButton *btn2 = [UIButton buttonWithType: UIButtonTypeRoundedRect];   
  7. btn2.frame = CGRectMake(60.0, 290.0, 200.0, 32.0);  
  8. [btn2 setTitle:@"從相機擷取圖片" forState:UIControlStateNormal];  
  9. [btn2 addTarget:self action:@selector(picker1) forControlEvents:UIControlEventTouchUpInside]; 

實現按鈕方法:

 
  1. // 從照片庫裡面選取  
  2.  
  3. -(void)picker  
  4.  
  5. {  
  6.  
  7. imagepicker = [[UIImagePickerController alloc] init];  
  8.  
  9. imagepicker.delegate = self;  
  10.  
  11. imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
  12. imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;  
  13. imagepicker.allowsEditing = YES;  
  14. [self presentModalViewController:self.imagepicker animated:YES];  
  15. }  
  16. // 從相機擷取  
  17. -(void)picker1  
  18. {  
  19. imagepicker = [[UIImagePickerController alloc] init];  
  20. imagepicker.delegate = self;  
  21. imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;  
  22. imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;  
  23. imagepicker.allowsEditing = YES;  
  24. [self presentModalViewController:self.imagepicker animated:YES];  

實現代理方法:

 
  1. // 初始化選取  
  2. - (void)imagePickerController:(UIImagePickerController *)picker   
  3. didFinishPickingImage:(UIImage *)image   
  4. editingInfo:(NSDictionary *)editingInfo  
  5. {  
  6. myImageView.image = image;  
  7. [[picker parentViewController] dismissModalViewControllerAnimated:YES];  
  8. }  
  9. // 完成選取  
  10.  
  11. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker  
  12. {  
  13. [picker dismissModalViewControllerAnimated:YES];  

小結:淺談iPhone手機拍照功能和照片庫選取功能調用的內容介紹完了,希望本文對你有所協助

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.