资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

iOSUITableView横向滑动点击UIButton放大-创新互联

    上篇博客已经介绍了如何使用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

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前标题:iOSUITableView横向滑动点击UIButton放大-创新互联
文章链接:http://cdkjz.cn/article/dcecdi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220