//保存cookies
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:@"url"]];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:cookies];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"abcaaa"];
NSData *cookiesdata = [[NSUserDefaults standardUserDefaults] objectForKey:@"abcaaa"];
if([cookiesdata length]) {
NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData:cookiesdata];
NSHTTPCookie *cookie;
for (cookie in cookies) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
}
}
/**
* 图片压缩
*
* @param image 原始图片
* @param maxPixel 最大边的像素
* @param quality 图片质量
*
* @return 压缩后的图片
*/
- (UIImage *)compressionImage:(UIImage *)image maxPixelValue:(float)maxPixel withCompressionQuality:(float)quality {
maxPixel = maxPixel / 2;
float maxValue = image.size.width > image.size.height ? image.size.width : image.size.height;
float scale = maxValue > maxPixel ? maxPixel / maxValue : 1;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(image.size.width * scale, image.size.height * scale), YES, [UIScreen mainScreen].scale);
[image drawInRect:CGRectMake(0, 0, image.size.width * scale, image.size.height * scale)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(newImage, quality);
UIImage *currentImage = [UIImage imageWithData:imageData];
return currentImage;
}
//呼吸灯效果
- (void)addShadowRadiusAnimation:(UIView *)view {
view.layer.shadowOpacity = 1;
view.layer.cornerRadius = 100.0f;
view.layer.shadowOffset = CGSizeMake(0, 0);
//加边框(正式项目可以去掉)
view.layer.borderWidth = 1;
view.layer.borderColor = [UIColor whiteColor].CGColor;
//加阴影
view.layer.shadowRadius = 1;
view.layer.shadowColor = [UIColor whiteColor].CGColor;
CABasicAnimation* baseAnimation = [CABasicAnimation animationWithKeyPath:@"shadowRadius"];
baseAnimation.fromValue = [NSNumber numberWithFloat:1];
baseAnimation.toValue = [NSNumber numberWithFloat:10];
baseAnimation.repeatCount = CGFLOAT_MAX;
baseAnimation.autoreverses = YES;
baseAnimation.duration = 1;
[view.layer addAnimation:baseAnimation forKey:@"shadowRadiusAnimation"];
}
//旋转
- (void)addRotationAnimation:(UIView *)view {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(2 * M_PI, 0.0, 0.0, 1.0)];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-M_PI, 0.0, 0.0, 1.0)];
animation.delegate = self;
animation.duration = 0.25;
animation.repeatCount = 2;
animation.cumulative = YES;
view.layer.ShouldRasterize = YES;
view.layer.rasterizationScale = 2;
[view.layer addAnimation:animation forKey:@"rotationAnimation"];
}