欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IOS打開照相機與本地相冊選擇圖片實例詳解

 更新時間:2017年06月20日 15:08:23   作者:HelloWord杰少  
這篇文章主要介紹了IOS打開照相機與本地相冊選擇圖片實例詳解的相關(guān)資料,需要的朋友可以參考下

IOS打開照相機與本地相冊選擇圖片

最近正好項目里面要集成“打開照相機與本地相冊選擇圖片”的功能,今天就在這邊給大家寫一個演示程序;打開相機拍攝后或者在相冊中選擇一張照片,然后將它顯示在界面上。好了廢話不多說,因為比較簡單直接上源碼。

首先,我們在頭文件中添加需要用到的actionSheet控件,顯示圖片的UIImageView控件,并且加上所需要的協(xié)議

#import <UIKit/UIKit.h> 
 
@interface ImagePickerViewController : UIViewController<UIImagePickerControllerDelegate,UIActionSheetDelegate,UINavigationControllerDelegate> 
 
@property (strong, nonatomic) IBOutlet UIImageView *headImage; 
 
@property (strong, nonatomic) UIActionSheet *actionSheet; 
 
- (IBAction)clickPickImage:(id)sender; 
@end 

通過點擊我設(shè)置在界面中的按鈕來呼出actionSheet控件,來選擇相應(yīng)的操作拍照或是在相冊中選擇相片,代碼如下:

// 
// ImagePickerViewController.m 
// testAuto 
// 
// Created by silicon on 15/5/9. 
// Copyright (c) 2015年 silicon. All rights reserved. 
// 
 
#import "ImagePickerViewController.h" 
 
@interface ImagePickerViewController () 
 
@end 
 
@implementation ImagePickerViewController 
 
@synthesize actionSheet = _actionSheet; 
 
- (void)viewDidLoad { 
  [super viewDidLoad]; 
  // Do any additional setup after loading the view from its nib. 
   
} 
 
- (void)didReceiveMemoryWarning { 
  [super didReceiveMemoryWarning]; 
  // Dispose of any resources that can be recreated. 
} 
 
 
/** 
 @ 調(diào)用ActionSheet 
 */ 
- (void)callActionSheetFunc{ 
  if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ 
    self.actionSheet = [[UIActionSheet alloc] initWithTitle:@"選擇圖像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"從相冊選擇", nil nil]; 
  }else{ 
    self.actionSheet = [[UIActionSheet alloc] initWithTitle:@"選擇圖像" delegate:self cancelButtonTitle:@"取消"destructiveButtonTitle:nil otherButtonTitles:@"從相冊選擇", nil nil]; 
  } 
   
  self.actionSheet.tag = 1000; 
  [self.actionSheet showInView:self.view]; 
} 
 
// Called when a button is clicked. The view will be automatically dismissed after this call returns 
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ 
  if (actionSheet.tag == 1000) { 
    NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    // 判斷是否支持相機 
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
      switch (buttonIndex) { 
        case 0: 
          //來源:相機 
          sourceType = UIImagePickerControllerSourceTypeCamera; 
          break; 
        case 1: 
          //來源:相冊 
          sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
          break; 
        case 2: 
          return; 
      } 
    } 
    else { 
      if (buttonIndex == 2) { 
        return; 
      } else { 
        sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
      } 
    } 
    // 跳轉(zhuǎn)到相機或相冊頁面 
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
    imagePickerController.delegate = self; 
    imagePickerController.allowsEditing = YES; 
    imagePickerController.sourceType = sourceType; 
     
    [self presentViewController:imagePickerController animated:YES completion:^{ 
     
    }]; 
  } 
} 
 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
  [picker dismissViewControllerAnimated:YES completion:^{ 
   
  }]; 
   
  UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
  self.headImage.image = image; 
} 
 
/* 
#pragma mark - Navigation 
 
// In a storyboard-based application, you will often want to do a little preparation before navigation 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
  // Get the new view controller using [segue destinationViewController]. 
  // Pass the selected object to the new view controller. 
} 
*/ 
 
- (IBAction)clickPickImage:(id)sender { 
   
  [self callActionSheetFunc]; 
} 
@end 

代碼比較簡單,也容易理解,運行的效果如下:

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • iOS中輸入框設(shè)置指定字符輸入的方法

    iOS中輸入框設(shè)置指定字符輸入的方法

    這篇文章主要給大家介紹了關(guān)于iOS中輸入框如何設(shè)置指定字符輸入的相關(guān)資料,其中介紹了關(guān)于只能輸入純數(shù)字、只能輸入純大小寫字母以及大小寫字母和數(shù)字結(jié)合輸入等指定字符的限制,需要的朋友可以參考借鑒,下面來一起看看吧。
    2018-01-01
  • IOS 中動畫的暫停與繼續(xù)播放的詳解

    IOS 中動畫的暫停與繼續(xù)播放的詳解

    這篇文章主要介紹了IOS 中動畫的暫停與繼續(xù)播放的詳解的相關(guān)資料,希望通過本文大家能理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-09-09
  • 淺談iOS開發(fā)如何適配暗黑模式(Dark Mode)

    淺談iOS開發(fā)如何適配暗黑模式(Dark Mode)

    這篇文章主要介紹了淺談iOS開發(fā)如何適配暗黑模式(Dark Mode),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • iOS自學(xué)筆記之XIB的使用教程

    iOS自學(xué)筆記之XIB的使用教程

    本篇文章主要介紹了iOS自學(xué)筆記之XIB的使用教程,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-01-01
  • ios開發(fā)Flutter構(gòu)建todo?list應(yīng)用

    ios開發(fā)Flutter構(gòu)建todo?list應(yīng)用

    這篇文章主要為大家介紹了ios開發(fā)Flutter構(gòu)建todo?list應(yīng)用實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • iOS開發(fā)實現(xiàn)抽屜效果

    iOS開發(fā)實現(xiàn)抽屜效果

    這篇文章主要為大家詳細介紹了iOS開發(fā)實現(xiàn)抽屜效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • iOS APP 多服務(wù)器環(huán)境分離的方法

    iOS APP 多服務(wù)器環(huán)境分離的方法

    這篇文章主要介紹了iOS APP 多服務(wù)器環(huán)境分離的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • iOS 高效的分頁加載實現(xiàn)示例

    iOS 高效的分頁加載實現(xiàn)示例

    本篇文章主要介紹了iOS 高效的分頁加載實現(xiàn)示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • iOS實現(xiàn)動態(tài)的開屏廣告示例代碼

    iOS實現(xiàn)動態(tài)的開屏廣告示例代碼

    啟動圖是在iOS開發(fā)過程中必不可少的一個部分,很多app在啟動圖之后會有一張自定義的開屏廣告圖,但是有的時候需要讓啟動圖看起來就是一個廣告,而且還要這個廣告里面會動,iOS的啟動圖只能是靜態(tài)的,而且固定,為了實現(xiàn)看起來的動畫效果,只能進行偽造了。下面來一起看看
    2016-09-09
  • 簡介iOS開發(fā)中應(yīng)用SQLite的模糊查詢和常用函數(shù)

    簡介iOS開發(fā)中應(yīng)用SQLite的模糊查詢和常用函數(shù)

    這篇文章主要介紹了iOS開發(fā)中應(yīng)用SQLite的模糊查詢和常用函數(shù),SQLite是一個可作嵌入式的數(shù)據(jù)庫非常適合小型應(yīng)用使用,需要的朋友可以參考下
    2015-12-12

最新評論