基础代码

http://blog.csdn.net/fightper

//保存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"];

}













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值