afnetworking传图片与其他参数

1.下面是我自己二次封装的afnetworking的函数,大家需要的可以参考一下

-(void)uploadCallBack:(void (^)(SKResponse *response))callBack setImage:(UIImage*)image{        

    NSData* data=[NSData dataWithData:UIImagePNGRepresentation(image)];    

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    [manager POST:_service.url parameters:self.dicParams constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

        [formData appendPartWithFileData:data //图片数据

                                    name:@"file" //参数名称

                                fileName:imageName //图片名称

                                mimeType:@"image/png"]; //上传的图片类型

    } success:^(AFHTTPRequestOperation *operation, NSDictionary* responseObject) {

//成功后的操作

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

//失败的操作

    }];

}


2.MJRefresh header 自定义

#import "JQQDIYRefreshHeader.h"

#import "CircleView.h"


#define ApplicationSize [[UIScreen mainScreen] bounds].size


@interface JQQDIYRefreshHeader ()


@property (nonatomic, strong)CircleView* circleView;

@property (nonatomic, strong)UIImageView* backImageView;

@property (nonatomic, strong)UIImageView* arowImageView;

@property (nonatomic, strong)UILabel* contentLabel;


@end


@implementation JQQDIYRefreshHeader{

    float percent;

}


#pragma mark 在这里做一些初始化配置(比如添加子控件)

- (void)prepare

{

    [super prepare];

    

    // 设置控件的高度

    self.mj_h = 70;

    percent = 0;

    

    self.backImageView = [[UIImageView alloc] initWithFrame:CGRectMake((ApplicationSize.width - 286.5)/2, 5, 286.5, 20)];

    self.backImageView.image = [UIImage imageNamed:@"logo"];

    [self addSubview:self.backImageView];

    

    float width = [HandleString lableWidth:@"下拉可以刷新..." withSize:CGSizeMake(100,20) withFont:Font(15)];

    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake((ApplicationSize.width-width)/2, 40, width, 20)];

    self.contentLabel.text = @"下拉可以刷新...";

    self.contentLabel.textColor = TextGrayColor;

    self.contentLabel.font = [UIFont systemFontOfSize:15];

    [self addSubview:self.contentLabel];

    

    self.circleView = [[CircleView alloc] initWithFrame:CGRectMake((ApplicationSize.width - width)/2 - 30, 40, 20, 20)];

    [self.circleView setStrokeEnd:0 animated:YES];

    [self addSubview:self.circleView];

    

    self.arowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(6.75, 5, 6.5, 10.5)];

    self.arowImageView.image = [UIImage imageNamed:@"icon-jiantou"];

    [self.circleView addSubview:self.arowImageView];

    

}


#pragma mark 在这里设置子控件的位置和尺寸

- (void)placeSubviews

{

    [super placeSubviews];

}


#pragma mark 监听scrollViewcontentOffset改变

- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change

{

    [super scrollViewContentOffsetDidChange:change];

}


#pragma mark 监听scrollViewcontentSize改变

- (void)scrollViewContentSizeDidChange:(NSDictionary *)change

{

    [super scrollViewContentSizeDidChange:change];

}


#pragma mark 监听scrollView的拖拽状态改变

- (void)scrollViewPanStateDidChange:(NSDictionary *)change

{

    [super scrollViewPanStateDidChange:change];

}


#pragma mark 监听控件的刷新状态

- (void)setState:(MJRefreshState)state

{

    MJRefreshCheckState;

    

    switch (state) {

        case MJRefreshStateIdle:

            self.contentLabel.text = @"下拉可以刷新...";

            [self.circleView setStrokeEnd:0 animated:YES];

            break;

        case MJRefreshStatePulling:

            self.contentLabel.text = @"松开立即刷新...";

            [self.circleView setStrokeEnd:percent animated:YES];

            break;

        case MJRefreshStateRefreshing:

            self.contentLabel.text = @"正在加载数据...";

            self.arowImageView.hidden = YES;

            [self.circleView circulation];

            break;

        default:

            break;

    }

}


#pragma mark 监听拖拽比例(控件被拖出来的比例)

- (void)setPullingPercent:(CGFloat)pullingPercent

{

    [super setPullingPercent:pullingPercent];

    percent = pullingPercent;

}


- (void)endRefreshing{

    [super endRefreshing];

    [self.circleView.circleLayer removeFromSuperlayer];

    [self.circleView addCircleLayer];

    [self.circleView setStrokeEnd:0 animated:YES];

    [self.circleView stopTimer];

    self.arowImageView.hidden = NO;

}

circleView是我自定义的一个控件,效果就是类似一个圆在转,大家可以把circleView换成label之类的控件,其实在MJRefresh github中的demo里有个diy文件夹,里面就是完全diy的下拉效果,上拉得实现也是类似的。大家还有不懂的,欢迎交流
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值