iOSUITableView橫向滑動(dòng)點(diǎn)擊UIButton放大

        上篇博客已經(jīng)介紹了如何使用UITableView橫屏滑動(dòng),本篇博客加上了點(diǎn)擊放大的操作,是放在UITableViewCell的cell上的,因?yàn)榭梢暬丶嗔?,故此隱藏掉,使用方法也很簡(jiǎn)單.userInteractionEnabled = false就可以了。

10多年建站經(jīng)驗(yàn), 網(wǎng)站制作、成都網(wǎng)站建設(shè)客戶的見(jiàn)證與正確選擇。成都創(chuàng)新互聯(lián)提供完善的營(yíng)銷型網(wǎng)頁(yè)建站明細(xì)報(bào)價(jià)表。后期開(kāi)發(fā)更加便捷高效,我們致力于追求更美、更快、更規(guī)范。

1.點(diǎn)擊UIButton中的圖片放大,首先要寫(xiě)UIButton的方法

2.改變控件大小的方法有很多,一個(gè)改變之后的大小,一個(gè)之前的大小

3.默認(rèn)是第一個(gè)選中,跟單選很像,那就定義一個(gè)標(biāo)記,然后每次點(diǎn)擊替換標(biāo)記,然后做對(duì)比是不是同一個(gè)標(biāo)記

4.然后就是刷新UITableView

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

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@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 進(jìn)行全局設(shè)置
    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

分享名稱:iOSUITableView橫向滑動(dòng)點(diǎn)擊UIButton放大
網(wǎng)頁(yè)網(wǎng)址:http://muchs.cn/article24/ighcje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、標(biāo)簽優(yōu)化、定制網(wǎng)站、GoogleApp開(kāi)發(fā)、服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)