码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 相机调用

时间:2014-11-25 14:27:43      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:localization   控件   ios开发   相机   

调用相机需要引入两个代理

UIImagePickerControllerDelegate,UINavigationControllerDelegate


否则出出现:

设置delegate时候,出现警告:Assigning to ‘id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>’ 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 ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {

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

        picker.delegate = self;

        picker.allowsEditing = YES;//设置可编辑

        /*sourceType = UIImagePickerControllerSourceTypeCamera; //照相机

         sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库

        sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片

         */

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentViewController:picker animated:YES completion:nil];//进入照相界面


    }

   

}

// 打开相册:(区分padiphone

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

   // for iphone

    UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

        pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        //pickerImage.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

        pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];

        

    }

    pickerImage.delegate = self;

    pickerImage.allowsEditing = NO;

    [self presentViewController:pickerImage animated:YES completion:nil];//进入照相界面

}


//for ipad:

-(void)ipadPicker{

    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

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

    UIImagePickerController *picker = [[UIImagePickerController alloc] 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 = [[UIPopoverController alloc]initWithContentViewController:picker];

    

    //permittedArrowDirections 设置箭头方向

    [popover presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

 

}



调用相机自定义《中文显示,相机全屏》

中文相机

   Iphone利用UIImagePickerController调用系统照相机一文中介绍了怎样调用系统照相机。但是有时候我需要自定义相机内容,需要以相机内容为背景,在其视图上添加其他控件,下面是相机试图最大化的实例。


-(void)onClickbutton:(id)sender

{

        UIImagePickerController *controller = [[UIImagePickerController alloc] init];

        [controller setSourceType:UIImagePickerControllerSourceTypeCamera];

        [controller setShowsCameraControls:NO];

        CGAffineTransform cameraTransform = CGAffineTransformMakeScale(1.25,1.25);

        controller.cameraViewTransform = cameraTransform;

        [self presentViewController:controller animated:YES completion:nil];//进入照相界面

}

targets->custom iOS target properties (Localization native development region设为China)



iOS 相机调用

标签:localization   控件   ios开发   相机   

原文地址:http://blog.csdn.net/u011374880/article/details/41480541

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!