iOS 相機調用

來源:互聯網
上載者:User

iOS 相機調用

調用相機需要引入兩個代理

UIImagePickerControllerDelegate,UINavigationControllerDelegate


否則出出現:

設定delegate時候,出現警告:Assigning to ‘id’ from incompatible type ‘AddSightingViewController *const __strong’

解決過程】

1.問題很明顯是 strong不相容,然後就去試試,把相應的AddSightingViewController改一下,從

@property (nonatomic)UIImagePickerController *imgPickerController;

改為:

@property (nonatomic,weak) UIImagePickerController *imgPickerController;

然後就消除了此警告了。

註:有時候Xcode不能及時消除警告和錯誤,需要手動去Product->Clean一下。

【總結】

好像Property變數,如果不指定參考型別,則預設是strong引用,此處改為weak,即可解除此警告。

而另外關於weak,strong等更詳細的含義,有空再整理。


//相機


-(void)takePhotoAction:(UIButton *)sender{

FZLog(nil, nil);

//先設定sourceType為相機,然後判斷相機是否可用(ipod)沒相機,不可用將sourceType設定為相片庫

if ([UIImagePickerControllerisSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {

UIImagePickerController *picker = [[UIImagePickerControlleralloc] init];//初始化

picker.delegate =self;

picker.allowsEditing =YES;//設定可編輯

/*sourceType = UIImagePickerControllerSourceTypeCamera; //照相機

sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //圖片庫

sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //儲存的相片

*/

picker.sourceType =UIImagePickerControllerSourceTypeCamera;

[selfpresentViewController:picker animated:YEScompletion:nil];//進入照相介面


}

}

// 開啟相簿:(區分pad和iphone)

-(void)openPhotosAction:(UIButton *)sender{

// for iphone:

UIImagePickerController *pickerImage = [[UIImagePickerControlleralloc] init];

if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

pickerImage.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

//pickerImage.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

pickerImage.mediaTypes = [UIImagePickerControlleravailableMediaTypesForSourceType:pickerImage.sourceType];

}

pickerImage.delegate =self;

pickerImage.allowsEditing =NO;

[selfpresentViewController:pickerImage animated:YEScompletion:nil];//進入照相介面

}


//for ipad:

-(void)ipadPicker{

UIImagePickerControllerSourceType sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

//sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //儲存的相片

UIImagePickerController *picker = [[UIImagePickerControlleralloc] init];

picker.delegate =self;

picker.allowsEditing =NO;//是否允許編輯

picker.sourceType = sourceType;

/*

如果從一個導覽按鈕處呈現,使用:

presentPopoverFromBarButtonItem:permittedArrowDirections:animated:;

如果要從一個視圖出呈現,使用:

presentPopoverFromRect:inView:permittedArrowDirections:animated:

如果裝置旋轉以後,位置定位錯誤需要在父視圖控制器的下面方法裡面重新置放:

didRotateFromInterfaceOrientation:(在這個方法體裡面重新設定rect)

然後再次調用:

- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated

*/

//UIPopoverController只能在ipad裝置上面使用;作用是用於顯示臨時內容,特點是總是顯示在當前視圖最前端,當單擊介面的其他地方時自動消失。

UIPopoverController *popover = [[UIPopoverControlleralloc]initWithContentViewController:picker];

//permittedArrowDirections 設定箭頭方向

[popover presentPopoverFromRect:CGRectMake(0,0, 300,300) inView:self.viewpermittedArrowDirections:UIPopoverArrowDirectionAnyanimated:YES];

}



調用相機自訂《中文顯示,相機全屏》

中文相機

在Iphone利用UIImagePickerController調用系統照相機一文中介紹了怎樣調用系統照相機。但是有時候我需要自訂相機內容,需要以相機內容為背景,在其視圖上添加其他控制項,下面是相機試圖最大化的執行個體。


-(void)onClickbutton:(id)sender

{

UIImagePickerController *controller = [[UIImagePickerControlleralloc] init];

[controller setSourceType:UIImagePickerControllerSourceTypeCamera];

[controllersetShowsCameraControls:NO];

CGAffineTransform cameraTransform = CGAffineTransformMakeScale(1.25,1.25);

controller.cameraViewTransform = cameraTransform;

[selfpresentViewController:controller animated:YEScompletion:nil];//進入照相介面

}

targets->custom iOS target properties (Localization native development region設為China)



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.