123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // UzysGroupPickerView.m
- // UzysAssetsPickerController
- //
- // Created by Uzysjung on 2014. 2. 13..
- // Copyright (c) 2014년 Uzys. All rights reserved.
- //
- // 版权属于原作者
- // http://code4app.com(cn) http://code4app.net(en)
- // 来源于最专业的源码分享网站: Code4App
- #import "UzysGroupPickerView.h"
- #import "UzysGroupViewCell.h"
- #import "UzysAssetsPickerController_Configuration.h"
- #define BounceAnimationPixel 5
- #define NavigationHeight kNavOffSet
- @implementation UzysGroupPickerView
- - (id)initWithGroups:(NSMutableArray *)groups
- {
- self = [super initWithFrame:CGRectZero];
- if (self) {
- // Initialization code
- self.groups = groups;
- [self setupLayout];
- [self setupTableView];
- [self addObserver:self forKeyPath:@"groups" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
- }
- return self;
- }
- - (void)dealloc
- {
- [self removeObserver:self forKeyPath:@"groups"];
- }
- - (void)setupLayout
- {
- //anchorPoint 를 잡는데 화살표 지점으로 잡아야함
- self.frame = CGRectMake(0, - [UIScreen mainScreen].bounds.size.height, kSize.width, kSize.height);;
- self.layer.cornerRadius = 4;
- self.clipsToBounds = YES;
- self.backgroundColor = [UIColor whiteColor];
-
- }
- - (void)setupTableView
- {
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavigationHeight, kSize.width, self.bounds.size.height -NavigationHeight) style:UITableViewStylePlain];
- self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
- self.tableView.contentInset = UIEdgeInsetsMake(1, 0, 0, 0);
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableView.dataSource = self;
- self.tableView.delegate = self;
-
- self.tableView.rowHeight = kGroupPickerViewCellLength;
- self.tableView.backgroundColor = [UIColor whiteColor];
- [self addSubview:self.tableView];
- }
- - (void)reloadData
- {
- [self.tableView reloadData];
- }
- - (void)show
- {
- [UIView animateWithDuration:0.25f delay:0.f options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionBeginFromCurrentState animations:^{
- self.frame = CGRectMake(0, BounceAnimationPixel , kSize.width, [UIScreen mainScreen].bounds.size.height);
- } completion:^(BOOL finished) {
- [UIView animateWithDuration:0.15f delay:0.f options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionBeginFromCurrentState animations:^{
- self.frame = CGRectMake(0, 0 , kSize.width, [UIScreen mainScreen].bounds.size.height);
- } completion:^(BOOL finished) {
- }];
- }];
- self.isOpen = YES;
- }
- - (void)dismiss:(BOOL)animated
- {
- if (!animated)
- {
- self.frame = CGRectMake(0, -[UIScreen mainScreen].bounds.size.height, kSize.width, [UIScreen mainScreen].bounds.size.height );
- }
- else
- {
- [UIView animateWithDuration:0.3f animations:^{
- self.frame = CGRectMake(0, - [UIScreen mainScreen].bounds.size.height, kSize.width, [UIScreen mainScreen].bounds.size.height);
- } completion:^(BOOL finished) {
- }];
- }
- self.isOpen = NO;
- }
- - (void)toggle
- {
- if(self.frame.origin.y <0)
- {
- [self show];
- }
- else
- {
- [self dismiss:YES];
- }
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.groups.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"kGroupViewCellIdentifier";
-
- UzysGroupViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil)
- {
- cell = [[UzysGroupViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
- }
- [cell applyData:[self.groups objectAtIndex:indexPath.row]];
- return cell;
- }
- #pragma mark - Table view delegate
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return kGroupPickerViewCellLength;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if(self.blockTouchCell)
- self.blockTouchCell(indexPath.row);
- }
- @end
|