iOS UITableView横向滑动点击UIButton放大
admin
2023-02-09 12:40:13
0

        上篇博客已经介绍了如何使用UITableView横屏滑动,本篇博客加上了点击放大的操作,是放在UITableViewCell的cell上的,因为可视化控件太多了,故此隐藏掉,使用方法也很简单.userInteractionEnabled = false就可以了。

1.点击UIButton中的图片放大,首先要写UIButton的方法

2.改变控件大小的方法有很多,一个改变之后的大小,一个之前的大小

3.默认是第一个选中,跟单选很像,那就定义一个标记,然后每次点击替换标记,然后做对比是不是同一个标记

4.然后就是刷新UITableView

#import "ViewController.h"
#import "FFTableViewCell.h"

@interface ViewController ()

@property(strong,nonatomic)UITableView *myTableView;
@property(strong,nonatomic)NSIndexPath *selectedIndexPath;
@end

@implementation ViewController

- (UITableView *)myTableView{
    if(!_myTableView){
        CGRect tableViewRect = CGRectMake(0, 0,100, CGRectGetWidth(self.view.frame));
        _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        _myTableView.frame = tableViewRect;
        _myTableView.separatorStyle = NO;
        _myTableView.backgroundColor = [UIColor grayColor];
        _myTableView.transform = CGAffineTransformMakeRotation(-M_PI / 2);
        _myTableView.showsVerticalScrollIndicator = NO;
        _myTableView.center = CGPointMake(self.view.frame.size.width / 2, 50);
    }
    return _myTableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //AppDelegate 进行全局设置
    if (@available(iOS 11.0, *)){
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    }
    
    self.view.backgroundColor = [UIColor purpleColor];
    [self.view addSubview:self.myTableView];
    
    self.selectedIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    // Do any additional setup after loading the view, typically from a nib.
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    FFTableViewCell *cell = [FFTableViewCell cellWithTableView:tableView];
    if([self.selectedIndexPath isEqual:indexPath]){
        [cell zoomPtoto:YES];
    }else{
        [cell zoomPtoto:NO];
    }
    return cell;
}

#pragma mark 选中的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    self.selectedIndexPath = indexPath;
    [self.myTableView reloadData];
}

- (void)dealloc{
    _myTableView = nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
#import "FFTableViewCell.h"

@interface FFTableViewCell()
@property(strong,nonatomic)UIButton *monthBtn;

@end

@implementation FFTableViewCell

static NSString *cellID = @"FFTableViewCell";

- (UIButton *)monthBtn{
    if(!_monthBtn){
        _monthBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _monthBtn.backgroundColor = [UIColor redColor];
        _monthBtn.layer.cornerRadius = 20.0f;
        _monthBtn.clipsToBounds = YES;
        [_monthBtn setTitle:@"在干嘛" forState:UIControlStateNormal];
        _monthBtn.titleLabel.font = [UIFont systemFontOfSize:11.0f];
        _monthBtn.userInteractionEnabled = false;
    }
    return _monthBtn;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    FFTableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell  = [[FFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        
        self.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
        [self.contentView addSubview:self.monthBtn];

    }
    return self;
}

- (void)zoomPtoto:(BOOL)isBool{
    _isBool = isBool;
    if(isBool){
        _monthBtn.layer.cornerRadius = 30.0f;
        _monthBtn.frame = CGRectMake((CGRectGetWidth(self.contentView.frame)-60)/2, (CGRectGetHeight(self.contentView.frame)-60)/2, 60,60);
    }else{
        
        _monthBtn.layer.cornerRadius = 20.0f;
        _monthBtn.frame = CGRectMake((CGRectGetWidth(self.contentView.frame)-40)/2, (CGRectGetHeight(self.contentView.frame)-40)/2, 40,40);
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    if(_isBool){
        _monthBtn.layer.cornerRadius = 30.0f;
        _monthBtn.frame = CGRectMake((CGRectGetWidth(self.contentView.frame)-60)/2, (CGRectGetHeight(self.contentView.frame)-60)/2, 60,60);
    }else{
        
        _monthBtn.layer.cornerRadius = 20.0f;
        _monthBtn.frame = CGRectMake((CGRectGetWidth(self.contentView.frame)-40)/2, (CGRectGetHeight(self.contentView.frame)-40)/2, 40,40);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc{
    _monthBtn = nil;
}

@end


相关内容

热门资讯

共促数智交融 共启丝路新篇—... 本报记者 亓玉昆7月22日,2026年世界互联网大会数字丝路发展论坛在陕西西安举行。论坛以“智汇丝路...
赛里木湖景区通报“工作人员殴打... 2026年7月23日17时许,赛里木湖景区入口处发生多名景区工作人员殴打旅游车司机事件,我们深感痛心...
继英伟达黄仁勋后,AMD苏姿丰... IT之家 7 月 24 日消息,随着中国开源 AI 模型的不断变强,近期美国业界出现了关于 AI 是...
辰奕智能获得实用新型专利授权:... 证券之星消息,根据天眼查APP数据显示辰奕智能(301578)新获得一项实用新型专利授权,专利名为“...
湖南湘江新区文化创意产业出海观... 中新网长沙7月23日电(胡语桐)在日本大型量贩门店的货架上,中国研发的视频创意软件实体产品陈列其中;...
中国数学家首次获得的菲尔兹奖“... 当地时间7月23日上午,2026年国际数学家大会在美国费城开幕,现场揭晓2026年菲尔兹奖得主。中国...
猪周期反转,这次可能来真的 市场过去几年关于猪周期的很多认知,现在需要重新审视了。过去几年,越来越多人相信:随着规模化养殖企业不...
王虹、邓煜为啥能获菲尔兹奖? 当地时间7月23日早晨,2026年国际数学家大会在美国费城开幕。国际数学联盟在开幕式上正式公布第二十...
高温津贴,不能用绿豆汤冲抵 近日,深圳市人力资源和社会保障局发布关于高温津贴的典型劳动仲裁案例,并普法提醒:即便劳动合同约定日薪...
菲律宾,你到底想干什么 中国和菲律宾关系,又出幺蛾子了。反正,最近几天,麻烦不断,场面火爆。仁爱礁,菲两艘小艇冲撞我巡逻船只...