高级UIKit-06(UIImagePickerController)

day07-1-getSystemImage】:获取系统相册

UIImagePickerController图片采集控制器

picker采集者,采摘者

该方法继承自:UINavigationController

该方法的简单使用:

1.创建该控制器,alloc init

2.present到这个控制器,会提示加载系统图片,加载完后默认按:

UIImagePickerControllerSourceTypePhotoLibrary样式显示。

有一个属性可以改变样式:sourceType

 

进入编辑模式:

首先打开编辑模式:allowsEditing设置为YES

打开编辑模式时为了可以保存编辑,需要实现UIImagePickerControllerDelegate代理的一个方法 


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

  这个方法可以通过info字典可以获取到图片的详细信息进行图片的操作。

在编辑模式下取消返回的话需要实现代理中的另一个方法: 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;

 在该方法里dismiss回去。

注意一定要设置图片采集控制器的delegate

 

如果在打开编辑模式下,点击图片会跳转到编辑图片界面,点击保存时调用imagePickerController方法,在关闭编辑模式下,点击图片就会调用imagePickerController方法。 

在进入图片采集控制器时还会调用UINavigationControllerDelegate的两个方法, 

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;

   该方法是在即将显示图片采集控制器的界面时调用。

 

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;

 该方法是在图片采集控制器的界面显示后调用。

可以在这两个方法中通过viewController对当前界面进行操作。

总结:

 删除图片达到后边图片往前挪的实现:

 1.先把图片从数组中删掉

 2.然后清空scrollview

 3.最后重新从新的数组中加载图片到scrollView

 

一个view只要从一个坐标系到另一个坐标系就需要进行转换。 

CGRect newRect = [self.imagesScrollViewconvertRect:imageView.frametoView:self.view];

 

imageview上添加按钮,只有用户交互打开了这个按钮才可以点。 

view放在最底下的方法是insertSubviewatIndex:0 

[self.editImageViewinsertSubview:self.editViewBackGroundIVatIndex:0]; // 把背景图片放在shuViews数组中的第0个位置,其效果也就是在最底下

  

使subview处于最前面

// 把点击的图片放在最前面

-(void)tapAction:(UITapGestureRecognizer *)tap{

    [self.editImageView bringSubviewToFront:tap.view]; // 使subview处于最前面

}

 

在放大缩小时,注意将scale属性设为1

在旋转图片时,注意将rotation属性设为0

 

保存view中的图片到系统相册中

// view中取出UIImage保存到相册中

- (IBAction)saveImageButton:(id)sender {

   

    // 创建画布

    UIGraphicsBeginImageContext(self.editImageView.bounds.size);

    // 把内容渲染到画布

    [self.editImageView.layer renderInContext:UIGraphicsGetCurrentContext()];

    // 取出画布中的图片

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    // 结束

    UIGraphicsEndImageContext();

    // 保存到系统相册中

    UIImageWriteToSavedPhotosAlbum(image, self@selector(image:didFinishSavingWithError:contextInfo:), Nil);

   

}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{

    UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"提示" message:@"保存成功" delegate:Nil cancelButtonTitle:@"确定" otherButtonTitles:Nilnil];

    [alert show];

}

 

day07-2-dragImage】:拖动图片到新的位置

常犯错误:忘记初始化数组

iosremove referencesmove to trash的区别?remove references 只是删除引用 工程文件夹里面还是有这个文件的 move to trash 把文件从工程文件夹里扔进垃圾箱里了 .

 

原文地址:https://www.cnblogs.com/yangmx/p/3561261.html