日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

滑动cell的时候执行动画效果

發(fā)布時間:2025/3/15 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 滑动cell的时候执行动画效果 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

滑動cell的時候執(zhí)行動畫效果

效果圖:

源碼:

// // ViewController.m // AniTab // // Created by XianMingYou on 15/2/26. // Copyright (c) 2015年 XianMingYou. All rights reserved. // #import "ViewController.h" #import "ShowCell.h"@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>@property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *dataSource;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// 初始化數(shù)據(jù)源self.dataSource = [NSMutableArray new];for (int i = 0; i < 40; i++) {[self.dataSource addObject:[NSString stringWithFormat:@"%02d YouXianMing", i]];}// 初始化tableViewself.tableView = [[UITableView alloc] initWithFrame:self.view.boundsstyle:UITableViewStylePlain];[self.view addSubview:self.tableView];self.tableView.delegate = self;self.tableView.dataSource = self;[self.tableView registerClass:[ShowCell class]forCellReuseIdentifier:@"ShowCell"]; }#pragma mark - tableView代理 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return self.dataSource.count; }- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {ShowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShowCell"];[cell accessData:self.dataSource[indexPath.row]];return cell; }#pragma mark cell顯示的時候 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {ShowCell *showCell = (ShowCell *)cell;[showCell show]; }#pragma mark cell消失的時候 - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath {ShowCell *showCell = (ShowCell *)cell;[showCell hide]; }#pragma mark cell高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {return 100; }@end

cell源碼:

// // ShowCell.h // AniTab // // Created by XianMingYou on 15/2/26. // Copyright (c) 2015年 XianMingYou. All rights reserved. // #import <UIKit/UIKit.h>@interface ShowCell : UITableViewCell/*** 動畫顯示*/ - (void)show;/*** 動畫隱藏*/ - (void)hide;/*** 處理數(shù)據(jù)** @param data 數(shù)據(jù)源*/ - (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"@interface ShowCellStoreValue : NSObject @property (nonatomic) CGRect startRect; @property (nonatomic) CGRect endRect; @end @implementation ShowCellStoreValue @end@interface ShowCell ()@property (nonatomic, strong) UILabel *label; @property (nonatomic, strong) ShowCellStoreValue *storeValue;@end@implementation ShowCell- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {self.label = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 300, 50)];self.label.font = [UIFont italicSystemFontOfSize:30.f];[self addSubview:self.label];self.storeValue = [ShowCellStoreValue new];self.storeValue.startRect = self.label.frame;self.storeValue.endRect = CGRectMake(10, 30 + 20, 300, 50);}return self; }- (void)accessData:(id)data {NSString *str = data;if ([str isKindOfClass:[NSString class]]) {self.label.text = str;} }/*** 動畫顯示*/ - (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

原理:

?

轉(zhuǎn)載于:https://www.cnblogs.com/YouXianMing/p/4300506.html

新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產(chǎn)品紅包拿不停!

總結(jié)

以上是生活随笔為你收集整理的滑动cell的时候执行动画效果的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。