iOS UITableView横向滑动点击UIButton放大
上篇博客已经介绍了如何使用UITableView横屏滑动,本篇博客加上了点击放大的操作,是放在UITableViewCell的cell上的,因为可视化控件太多了,故此隐藏掉,使用方法也很简单.userInteractionEnabled = false就可以了。
1.点击UIButton中的图片放大,首先要写UIButton的方法
2.改变控件大小的方法有很多,一个改变之后的大小,一个之前的大小
3.默认是第一个选中,跟单选很像,那就定义一个标记,然后每次点击替换标记,然后做对比是不是同一个标记
4.然后就是刷新UITableView
#import"ViewController.h"#import"FFTableViewCell.h"@interfaceViewController()<UITableViewDelegate,UITableViewDataSource>@property(strong,nonatomic)UITableView*myTableView;@property(strong,nonatomic)NSIndexPath*selectedIndexPath;@end@implementationViewController-(UITableView*)myTableView{if(!_myTableView){CGRecttableViewRect=CGRectMake(0,0,100,CGRectGetWidth(self.view.frame));_myTableView=[[UITableViewalloc]initWithFrame:CGRectZerostyle:UITableViewStylePlain];_myTableView.dataSource=self;_myTableView.delegate=self;_myTableView.frame=tableViewRect;_myTableView.separatorStyle=NO;_myTableView.backgroundColor=[UIColorgrayColor];_myTableView.transform=CGAffineTransformMakeRotation(-M_PI/2);_myTableView.showsVerticalScrollIndicator=NO;_myTableView.center=CGPointMake(self.view.frame.size.width/2,50);}return_myTableView;}-(void)viewDidLoad{[superviewDidLoad];//AppDelegate进行全局设置if(@available(iOS11.0,*)){[[UIScrollViewappearance]setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];}self.view.backgroundColor=[UIColorpurpleColor];[self.viewaddSubview:self.myTableView];self.selectedIndexPath=[NSIndexPathindexPathForRow:0inSection:0];//Doanyadditionalsetupafterloadingtheview,typicallyfromanib.}-(CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath*)indexPath{return100;}-(NSInteger)tableView:(UITableView*)tableViewnumberOfRowsInSection:(NSInteger)section{return50;}-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath{FFTableViewCell*cell=[FFTableViewCellcellWithTableView:tableView];if([self.selectedIndexPathisEqual:indexPath]){[cellzoomPtoto:YES];}else{[cellzoomPtoto:NO];}returncell;}#pragmamark选中的方法-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath{[tableViewdeselectRowAtIndexPath:indexPathanimated:YES];self.selectedIndexPath=indexPath;[self.myTableViewreloadData];}-(void)dealloc{_myTableView=nil;}-(void)didReceiveMemoryWarning{[superdidReceiveMemoryWarning];//Disposeofanyresourcesthatcanberecreated.}@end#import"FFTableViewCell.h"@interfaceFFTableViewCell()@property(strong,nonatomic)UIButton*monthBtn;@end@implementationFFTableViewCellstaticNSString*cellID=@"FFTableViewCell";-(UIButton*)monthBtn{if(!_monthBtn){_monthBtn=[UIButtonbuttonWithType:UIButtonTypeCustom];_monthBtn.backgroundColor=[UIColorredColor];_monthBtn.layer.cornerRadius=20.0f;_monthBtn.clipsToBounds=YES;[_monthBtnsetTitle:@"在干嘛"forState:UIControlStateNormal];_monthBtn.titleLabel.font=[UIFontsystemFontOfSize:11.0f];_monthBtn.userInteractionEnabled=false;}return_monthBtn;}-(void)awakeFromNib{[superawakeFromNib];//Initializationcode}+(instancetype)cellWithTableView:(UITableView*)tableView{FFTableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:cellID];if(cell==nil){cell=[[FFTableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellID];}returncell;}-(instancetype)initWithStyle:(UITableViewCellStyle)stylereuseIdentifier:(NSString*)reuseIdentifier{self=[superinitWithStyle:stylereuseIdentifier:reuseIdentifier];if(self){self.contentView.transform=CGAffineTransformMakeRotation(M_PI/2);[self.contentViewaddSubview:self.monthBtn];}returnself;}-(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{[superlayoutSubviews];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)selectedanimated:(BOOL)animated{[supersetSelected:selectedanimated:animated];//Configuretheviewfortheselectedstate}-(void)dealloc{_monthBtn=nil;}@end
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。