- 将第三方SDWebImage导入到工程, 将原ARC的第三方加入到非MRC工程后,选择Build Phases然后在搜索框中收索SD,全部选中后回车,在弹出的框中添加-fobjc-arc
- 强制不报黄方法:#pragma clang diagnostic ignored “-Wignored-attributes”, 其中-Wignored-attributes为报黄原因
- 简单运用ViewController.m文件
#import "ViewController.h"
#import "UIImageView+WebCache.h"//网络缓存图片
#import "UIImage+GIF.h"//动画图片
@interface ViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property(nonatomic,retain)UIImageView *imageview;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.imageview = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
self.imageview.backgroundColor = [UIColor yellowColor];
[self.view addSubview:self.imageview];
[_imageview release];
[self.imageview sd_setImageWithURL:[NSURL URLWithString:@"http://v.juhe.cn/movie/picurl?2583083"]];
self.imageview.image = [UIImage sd_animatedGIFNamed:@"])EHD9MH4@C05%`J}K}O8J7"];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册中取", nil];
[actionSheet showInView:self.view];
[actionSheet release];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
self.imageview.userInteractionEnabled = YES;
longPress.minimumPressDuration = 2;
[self.imageview addGestureRecognizer:longPress];
[longPress release];
}
#pragma mark UIActionSheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:^{
}];
}
}
- (void)longPress:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan) {
UIImageWriteToSavedPhotosAlbum(self.imageview.image, nil, nil, nil);
}
}
#pragma mark UIImagePickerController delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:^{
}];
UIImage *image = info[UIImagePickerControllerEditedImage];
self.imageview.image = image;
}