zoukankan      html  css  js  c++  java
  • 如何获取UITableView中cell的frame值

    如何获取UITableView中cell的frame值

    这个可以用来处理UITableView弹出键盘的问题

    本人视频教程系类   iOS中CALayer的使用

    效果:

    源码:

    //
    //  ViewController.m
    //  TableViewCellFrame
    //
    //  Created by YouXianMing on 14/12/24.
    //  Copyright (c) 2014年 YouXianMing. All rights reserved.
    //
    
    #import "ViewController.h"
    
    static NSString *YOU_XIAN_MING = @"REUSED_FLAG";
    
    @interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
    
    @property (nonatomic, strong) UITableView  *tableView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        // 关闭状态栏
        [UIApplication sharedApplication].statusBarHidden = YES;
    
        // 创建tableView
        [self createTableView];
    }
    
    #pragma mark - TableView相关
    - (void)createTableView {
        self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds
                                                      style:UITableViewStylePlain];
        self.tableView.delegate   = self;
        self.tableView.dataSource = self;
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:YOU_XIAN_MING];
        [self.view addSubview:self.tableView];
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 20;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell    = [tableView dequeueReusableCellWithIdentifier:YOU_XIAN_MING];
        cell.textLabel.text      = [NSString stringWithFormat:@"YouXianMing - %02ld", (long)indexPath.row];
        cell.textLabel.textColor = [UIColor grayColor];
        
        return cell;
    }
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // 获取对应cell的rect值(其值针对于UITableView而言)
        CGRect rect = [self.tableView rectForRowAtIndexPath:indexPath];
        
        // 做动画效果
        NSLog(@"%@", NSStringFromCGRect(rect));
        [self.tableView setContentOffset:CGPointMake(rect.origin.x, rect.origin.y)
                                animated:YES];
    }
    
    @end

    关键的地方:

  • 相关阅读:
    Django(四)
    Django(三)
    Django(二)
    Django 基础篇
    jQuery
    JDK,JRE,JVM区别与联系
    webdriver API中文文档
    selenium及webdriver的原理
    JAVA IO流结构图
    抽象工厂与工厂方法的区别
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4182242.html
Copyright © 2011-2022 走看看