2013-07-10 8 views
7

Tôi đã tự hỏi làm thế nào Snapchat hoạt hình mà ma điều khi bạn kéo xuống để làm mới? Tôi muốn thực hiện điều đó trong ứng dụng của mình và tự hỏi nó đã được thực hiện như thế nào.Trình tải hoạt ảnh như Snapchat

+0

Tôi đã tìm kiếm khắp nơi một cách để sử dụng Core Animation với UIRefreshControl, hoặc thông tin về làm thế nào để làm cho một pull-to-refresh từ đầu vì vậy tôi có thể thêm hình ảnh động. Chỉ cần nhìn thấy Snapchat của hoạt hình refresher, do đó, nó hoàn toàn có thể. Tôi đang đặt một tiền thưởng về điều này. – user

+3

Tôi khá chắc chắn nó chỉ là một kéo thường xuyên để làm mới, kéo dài ma, sau đó làm một hình ảnh động tùy chỉnh. Đây là điều gần nhất tôi có thể tìm thấy. https://www.cocoacontrols.com/controls/spiralpulltorefresh –

+3

Ai downvoted - hãy giải thích những quy tắc hoặc giao thức nào đang bị vi phạm. – user

Trả lời

7

Tôi nghĩ bạn cần viết giải pháp của riêng mình. Nhưng nó thực sự không phải là khó.

Bạn cần tạo chế độ xem tiêu đề bảng tùy chỉnh chứa hình ảnh có thể kéo dài và thực hiện một số thao tác trong UITableViewDelegate. Dưới đây là một triển khai khá chung chung về xử lý kiểm soát làm mới tùy chỉnh.

1) tạo ra một UIView tùy chỉnh để phục vụ như xem chỉ kéo xuống của bạn:

header file:

#import <UIKit/UIKit.h> 

typedef enum UpdateListViewState 
{ 
    UpdateListViewStatePull, 
    UpdateListViewStateRelease, 
    UpdateListViewStateUpdate 

}UpdateListViewState; 


@interface UpdateListView : UIView 
@property (nonatomic,readwrite) UpdateListViewState state; 
@property (nonatomic,strong) UIImageView imageView; 
@end 

2) Giao headerView như tiêu đề tableView:

self.header = [[UpdateListView alloc] init]; 
self.table.tableHeaderView = self.header; 

3) Trong UITableViewDelegate của bạn , Thực hiện xử lý cuộn bảng:

const int UPDATE_DRAG_HEIGHT = -70; 

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 
{ 
    if (self.header.state == UpdateListViewStateRelease) { 
     //Perform update stuff here & perhaps refresh animation 
     self.header.state = UpdateListViewStateInitial; 

    } 
} 

-(void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    //adjust size of self.header.imageView here according to scrollView.ContentOffset 
    if (scrollView.contentOffset.y < UPDATE_DRAG_HEIGHT && self.header.state != UpdateListViewStateUpdate) { 
      self.header.state = UpdateListViewStateRelease; 
    } 
}