日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

滑動cell的時候執行動畫效果

效果圖:

源碼:

// // 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];// 初始化數據源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;/*** 處理數據** @param data 數據源*/ - (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

原理:

?

轉載于:https://www.cnblogs.com/YouXianMing/p/4300506.html

新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。