消亡缓存的UIActionSheet,访谈系统相册功用完毕

作者: 计算机网络  发布:2019-11-30

撤消缓存的UIActionSheet,缓存uiactionsheet

 

点击任什么地点,现身提示:

 

图片 1

 

 

代码:

 

//点击任哪个地区冒出sheet

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"明确要清空图片缓存?" delegate:self cancelButtonTitle:@"裁撤" destructiveButtonTitle:@"鲜明" otherButtonTitles:nil, nil];

    [sheet showInView:self.view];

}

 

咱们在做应用进度中,难免会蒙受要安装客户头像这样的机能,作者这边总结了多个调用系统相机,相册的效能达成,写出来与大家享用,如有不足还请指正: 1.我们在调用那些意义的时候,经常都有个用来填充图片的ImageView和点击ImageView触发此方法的风浪,这里自身就写个ImageView和Button来演示,下边是达成整个职能的代码:

怎在金立中的UIActionSheet动态增进开关?

给你看看这段代码:UIActionSheet *sheet = [[UIActionSheet alloc] init];[sheet addButtonWithTitle:@"Button 1"];if (useDestructiveButton) { [sheet setDestructiveButtonIndex:[sheet addButtonWithTitle:@"Button 2"]];}  

import "ViewController.h"

怎更改过UIActionSheet的背景颜色

UIImageView *buttonbackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_background"]];
[UIActionSheet addSubview:buttonbackgroundView];
想加什么样图片或然换颜色,随你便  

点击任哪个地点,现身提醒: 代码: //点击任哪个地方现身sheet -(void卡塔尔国touchesBegan:(NSSet *)touches withEvent:(UIEvent *)...

define kWidth [UIScreen mainScreen].bounds.size.width

define kHeight [UIScreen mainScreen].bounds.size.height

@interface ViewController () { BOOL isFullScreen; } @property(nonatomic,strong)UIImageView *imageView;

@end

@implementation ViewController

(void)viewDidLoad { [super viewDidLoad];

_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]; _imageView.backgroundColor = [UIColor grayColor]; [self.view addSubview:_imageView];

UIButton *chooseBtn = [UIButton buttonWithType:UIButtonTypeCustom]; chooseBtn.frame = CGRectMake(100, 30, 100, 40); [chooseBtn addTarget:self action:@selector(chooseImage:) forControlEvents:UIControlEventTouchUpInside]; [chooseBtn setBackgroundColor:[UIColor brownColor]]; [chooseBtn setTitle:@"选拔照片" forState:UIControlStateNormal]; [self.view addSubview:chooseBtn];

}

pragma mark - 保存图片至沙盒

(void) saveImage:(UIImage)currentImage withName:(NSString)imageName {

NSDataimageData = UIImageJPEGRepresentation(currentImage, 0.5卡塔尔国; // 获取沙盒目录 NSStringfullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];

// 将图片写入文件 [imageData writeToFile:fullPath atomically:NO]; }

pragma mark - image picker delegte

(void)imagePickerController:(UIImagePickerController)picker didFinishPickingMediaWithInfo:(NSDictionary)info { [picker dismissViewControllerAnimated:YES completion:^{}];

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

[self saveImage:image withName:@"currentImage.png"];

NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"currentImage.png"];

UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath];

isFullScreen = NO; [self.imageView setImage:savedImage];

self.imageView.tag = 100;

}

(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissViewControllerAnimated:YES completion:^{}]; }

-(void)touchesBegan:(NSSet)touches withEvent:(UIEvent)event {

isFullScreen = !isFullScreen;UITouch *touch = [touches anyObject];CGPointtouchPoint = [touch locationInView:self.view];CGPointimagePoint =self.imageView.frame.origin;//touchPoint.x ,touchPoint.y 就是触点的坐标// 触点在imageView内,点击imageView时 放大,再一次点击时减少if(imagePoint.x<= touchPoint.x&& imagePoint.x+self.imageView.frame.size.width>=touchPoint.x&& imagePoint.y<=  touchPoint.y&& imagePoint.y+self.imageView.frame.size.height>= touchPoint.y卡塔尔(英语:State of Qatar){// 设置图片放大动漫[UIViewbeginAnimations:nilcontext:nil];// 动漫时间[UIViewsetAnimationDuration:1];if(isFullScreen卡塔尔 {// 放大尺寸self.imageView.frame= CGRectMake(0,0, kWidth, kHeight卡塔尔(英语:State of Qatar);    }else{// 收缩尺寸self.imageView.frame= CGRectMake(100,100,200,200卡塔尔(英语:State of Qatar);    }// commit动漫[UIViewcommitAnimations];}

}

pragma mark - actionsheet delegate

-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (actionSheet.tag == 255) {

NSUInteger sourceType =0;// 剖断是还是不是援救相机if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]卡塔尔(英语:State of Qatar){switch(buttonIndex卡塔尔(قطر‎ {case0:// 打消return;case1:// 相机sourceType = UIImagePickerControllerSourceTypeCamera;break;case2:// 相册sourceType = UIImagePickerControllerSourceTypePhotoLibrary;break;        }    }else{if(buttonIndex ==0卡塔尔(قطر‎ {return;        }else{            sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;        }    }// 跳转到相机或相册页面UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];    imagePickerController.delegate=self;    imagePickerController.allowsEditing=YES;    imagePickerController.sourceType= sourceType;    [selfpresentViewController:imagePickerController animated:YEScompletion:^{}];}

}

(void)chooseImage:(UIButton *)btn {

UIActionSheet *sheet;

// 推断是不是扶植相机 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { sheet = [[UIActionSheet alloc] initWithTitle:@"选拔" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"撤除" otherButtonTitles:@"拍照",@"从相册选用", nil]; } else {

sheet = [[UIActionSheet alloc] initWithTitle:@"采取"delegate:selfcancelButtonTitle:nildestructiveButtonTitle:@"打消"otherButtonTitles:@"从相册选用",nil];

}

sheet.tag = 255;

[sheet showInView:self.view];

} @end

2.离奇的是大家不签代理,功用也能兑现,为了有限支撑起见,仍然签定代理;到此,要贯彻的基本成效已经完全展现出来了,大家再依附本身项目标需求来改动就能够了。 希望对我们有着扶植。

本文由今晚开什么码发布于计算机网络,转载请注明出处:消亡缓存的UIActionSheet,访谈系统相册功用完毕

关键词: