Animate when you slide the cell
:
Source:
////VIEWCONTROLLER.M//Anitab////Created by Xianmingyou on 15/2/26.//Copyright (c) 2015 xianmingyou. All rights reserved.//#import "ViewController.h"#import "ShowCell.h"@interfaceViewcontroller () <uitableviewdatasource, uitableviewdelegate>@property (nonatomic, strong) UITableView*TableView, @property (nonatomic, strong) Nsmutablearray*DataSource;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //initializing the data sourceSelf.datasource = [NsmutablearrayNew]; for(inti =0; I < +; i++) {[Self.datasource addobject:[nsstring stringWithFormat:@"%02d youxianming", I]]; } //Initialize TableViewSelf.tableview =[[UITableView alloc] InitWithFrame:self.view.bounds Style:uitablevie Wstyleplain]; [Self.view AddSubview:self.tableView]; Self.tableview.Delegate=Self ; Self.tableView.dataSource=Self ; [Self.tableview Registerclass:[showcellclass] Forcellreuseidentifier:@"Showcell"];}#pragmaMark-tableview Agent-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {returnSelf.dataSource.count;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {Showcell*cell = [TableView dequeuereusablecellwithidentifier:@"Showcell"]; [Cell Accessdata:self.datasource[indexpath.row]]; returncell;}#pragmaWhen Mark Cell is displayed-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: (Nsindexpath *) Indexpath {Showcell*showcell = (Showcell *) cell; [Showcell show];}#pragmaWhen Mark Cell disappears-(void) TableView: (UITableView *) TableView Didenddisplayingcell: (UITableViewCell *) cell Forrowatindexpath: (nsindexpath*) Indexpath {Showcell*showcell = (Showcell *) cell; [Showcell hide];}#pragmaMark Cell Height-(cgfloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath {return -;}@end
Cell Source:
////ShowCell.h//Anitab////Created by Xianmingyou on 15/2/26.//Copyright (c) 2015 xianmingyou. All rights reserved.//#import<UIKit/UIKit.h>@interfaceShowcell:uitableviewcell/** * Animated display*/- (void) show;/** * Animated Hide*/- (void) Hide;/** * processing Data * * @param data source*/- (void) AccessData: (ID) data;@end
////SHOWCELL.M//Anitab////Created by Xianmingyou on 15/2/26.//Copyright (c) 2015 xianmingyou. All rights reserved.//#import "ShowCell.h"@interfaceShowcellstorevalue:nsobject@property (nonatomic) CGRect startrect; @property (nonatomic) cgrect endRect;@end@implementationShowcellstorevalue@end@interfaceShowcell () @property (nonatomic, strong) UILabel*label; @property (Nonatomic, strong) Showcellstorevalue*Storevalue;@end@implementationShowcell-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) Reuseidentifier {if(self =[Super Initwithstyle:style Reuseidentifier:reuseidentifier]) {Self.label= [[UILabel alloc] Initwithframe:cgrectmake (Ten, -, -, -)]; Self.label.font= [Uifont italicsystemfontofsize: -. f]; [Self AddSubview:self.label]; Self.storevalue= [ShowcellstorevalueNew]; Self.storeValue.startRect=Self.label.frame; Self.storeValue.endRect= CGRectMake (Ten, -+ -, -, -); } returnSelf ;}- (void) AccessData: (ID) Data {nsstring*str =data; if([Str iskindofclass:[nsstringclass]]) {Self.label.text=str; }}/** * Animated display*/- (void) Show {[UIView animatewithduration:1. F animations:^{self.label.frame=Self.storeValue.endRect; }];}- (void) Hide {[Self.label.layer removeallanimations]; Self.label.frame=Self.storeValue.startRect;}@end
Principle:
Animate when you slide a cell