图片相关 UIActionSheet
来源:互联网 发布:阿里云域名解析 速度 编辑:程序博客网 时间:2024/05/21 00:46
ViewController.m
#import "ViewController.h"#import "UIImageView+WebCache.h"#import "UIImage+GIF.h"@interface ViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>@property(nonatomic,retain)UIImageView *myImage;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.myImage=[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]; self.myImage.backgroundColor=[UIColor yellowColor]; [self.view addSubview:self.myImage]; [_myImage release]; [self.myImage sd_setImageWithURL:[NSURL URLWithString:@"http://v.juhe.cn/movie/picurl?2583246"]]; // 创建一个UIActionSheet UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选取", nil]; [sheet showInView:self.view]; self.myImage.userInteractionEnabled=YES; UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)]; [self.myImage addGestureRecognizer:longPress]; [longPress release]; }-(void)longPressAction:(UILongPressGestureRecognizer *)longPress{ NSLog(@"%@",@"lalala"); // 判断手势当前的状态,只有刚开始会保存图片 if (longPress.state==UIGestureRecognizerStateBegan) { // 把图片写到本地相册中 UIImageWriteToSavedPhotosAlbum(self.myImage.image, nil, nil, nil); }}-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"%ld",buttonIndex); if (buttonIndex==0) { UIImagePickerController *picker=[[UIImagePickerController alloc]init]; // 设置代理人 // 这个地方很特殊,这个代理人执行两套协议,需要签订两个协议 picker.delegate=self; // 允许进行编辑 picker.allowsEditing=YES; // 用模态让他显示出来 [self presentViewController:picker animated:YES completion:^{ }]; } }#pragma mark 点击choose之后,可以选中当前的图片,并且返回让图片显示在imageView上-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ // 隐藏的效果就取消了,所以,我们需要手动添加dismiss的方法,让相册消失 [self dismissViewControllerAnimated:YES completion:^{ }]; NSLog(@"%@",info); // 从返回过来的字典对象info中提取image UIImage *image=info[UIImagePickerControllerOriginalImage]; self.myImage.image=image; }
0 0
- 图片相关 UIActionSheet
- UI13_数据解析之图片相关(UIActionSheet,UIImagePickerController, UINavigationController协议方法)
- Objective - C UIActionSheet 图片相关 将选中图片放在指定位置并适应大小,长按保存
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- UIActionSheet
- 友元函数的正确用法和滥用方法
- JAVA_SE基础——25.面向对象练习
- zoj Count the Colors 1610 (数组模拟&&线段树)好题
- uestc 360(区间合并)
- 《断舍离》笔记三
- 图片相关 UIActionSheet
- apache wicket 7.X让html回归webapp目录下
- 第六讲:用户界面 View(二)
- oracle函数
- poj 2186 强连通分量
- 中庸处世,不落俗套
- 增量学习
- 创建基于本地协议的git服务器
- 第七讲:用户界面 View(三)