tableview中加一个tableview,点击后取消tableview

iOS动画与UITableView实践
本文介绍了一个使用UITableView展示数组元素的iOS应用实例,并通过动画效果实现了控件的隐藏与显示功能。

老大,今天又深深地鄙视了我一把!~!~!~!……

怪不得老大又失恋了!~!呵呵  窃喜一下  步入正题:我得好好学习了。不能光让我们的老大带我写代码了   我得自己学习学习了。

老大经常说的一句“真棒”,“你就不能自己学习啊!”好吧,今天我自己总结一下。别废话了   再废话就下班了!~!


进入代码行列::::::::::

 实现这个效果   需要3点:

1.重新写个类去调用

2.动画去完成

3.新建数组,不要数组写在一起


————> 

1.TableSelectView.h文件

#import <UIKit/UIKit.h>

@interface TableSelectView : UIView<UITableViewDataSource,UITableViewDelegate>

{

    NSArray *titleArr;                   //创建数组

    UITableView *table;             //创建UITableView

}

@end

TableSelectView.m文件

#import "TableSelectView.h"

@implementation TableSelectView

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        table=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStyleGrouped];    //初始化

        table.delegate=self;                 //delegate

        table.dataSource=self;           //dataSource

        [self addSubview:table];        //table添加到self中

        titleArr=[[NSArray alloc] initWithObjects:@"中文",@"英文",@"泰文", nil];         //数组分类

    }

    return self;                           //返回

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section          //section的个数

{

    return [titleArr count];       //返回数组的个数

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{                           //返回几个cell

    return  1;

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath          //显示属性风格

{

    static NSString *CellIdentifier = @"SvTableViewCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    cell.showsReorderControl = YES;

    cell.accessoryType = UITableViewCellStyleValue1;

    cell.textLabel.texttitleArr[indexPath.row];

    return cell;

}

@end



------------------------->

2.动画

ViewController.h文件

#import <UIKit/UIKit.h>

#import "TableSelectView.h"

@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>

{

    TableSelectView *selectTable;         

    UIControl *contrl;        //UIKit提供了一组空间:UISwitch开关 UIButton按钮 UISegmentedControl分段控件   UISlider滑块  UITestField文本字段控件 UIPageControl分页控件

}

@end


ViewController.m文件

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, retain) UISwitch *airplaneModeSwitch;

@end

@implementation ViewController

@synthesize airplaneModeSwitch = _airplaneModeSwitch;

- (void)viewDidLoad

    {

        [super viewDidLoad];

        self.airplaneModeSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];

        [self drawTableView];

        //-------------------------------------------------------------------------

        selectTable=[[TableSelectView alloc] initWithFrame:CGRectMake(20, 150, 280,200)];                                            //新建的tableview的大小  

        contrl=[[UIControl alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width,  [UIScreen mainScreen].bounds.size.height)];                               //控件的大小

        [contrl addTarget:self action:@selector(ClickeCon:) forControlEvents:UIControlEventTouchUpInside];    //给控件添加触发事件

        [contrl addSubview:selectTable];                                      //新建的tableview添加到控件中

        [self.view addSubview:contrl];                                          //把控件添加到view中

    }

-(void)ClickeCon:(UIControl *)con                                         //按钮的事件

{

    [UIView beginAnimations:nil context:nil];                         //开始动画

    contrl.frame=CGRectMake(0,[UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width,  [UIScreen mainScreen].bounds.size.height);

    [UIView setAnimationDuration:2];                                     //设置动画淡入淡出

    [UIView commitAnimations];                                               //类方法开始一个动画块并用commitAnimations类方法结束

}

-(void)StartAnimation

{

    [UIView beginAnimations:nil context:nil];

    contrl.frame=CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width,  [UIScreen mainScreen].bounds.size.height);

    [UIView setAnimationDuration:2];

    [UIView commitAnimations];

}




if (indexPath.section ==2) {

        //语言选择

        [self StartAnimation];    //调用一下即可

        

    }







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值