您的位置:首页 > 产品设计 > UI/UE

UI 和图片相关的知识点

2015-12-25 17:22 417 查看

UIActionSheet的初始化方法

UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"图片" delegate:self cancelButtonTitle:@"two" destructiveButtonTitle:@"从相册选取" otherButtonTitles:@"four", nil];
[action showInView:self.view];


UIImagePickerController(图片选择器) 1.初始化 2.设置代理人 3.允许编辑 allowsEditing 4.模态跳转 presentViewController ------>在action的点击事件里写

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
//    NSLog(@"%ld", buttonIndex);

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
// 设置代理人
picker.delegate = self;
// 允许编辑
picker.allowsEditing = YES;
// 模态进行跳转
[self presentViewController:picker animated:YES completion:^{

}];

}


从本地选取图片 1.dismiss回第一页面 2.从字典里提取info里图片的内容------>imagePicker里写 ------>字典中的key有两个,两种不同的状态

// 从本地选取图片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
//
[picker dismissViewControllerAnimated:YES completion:^{

}];
//    NSLog(@"%@", info);
// 从字典里提取info里的图片内容
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.image = image;

}


将图片存为本地 1.首先需要打开交互userInteractionEnabled 2.创建一个长按的手势 3.在长按的手势里,将图片保存在本地相册, 后面三个参数主要作为保存之后的信息回调,把保存的结果返回

self.imageView.userInteractionEnabled = YES;
UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpressAction:)];
[self.imageView addGestureRecognizer:longpress];


- (void)longpressAction:(UILongPressGestureRecognizer *)longpress{
// 把图片保存到本地相册
// 后面三个参数主要是作为保存之后的信息回调,把保存的结果返回
UIImageWriteToSavedPhotosAlbum(self.imageView.image, nil, nil, nil);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: