Animate when you slide the cell

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.