-(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 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
[super scrollViewContentOffsetDidChange:change];
}
#pragma mark 监听scrollView的contentSize改变
- (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的下拉效果,上拉得实现也是类似的。大家还有不懂的,欢迎交流