iOS版动画表视图单元为全屏幕横置时 [英] iOS Animate table view cell into full screen when tapped

查看:180
本文介绍了iOS版动画表视图单元为全屏幕横置时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现,因为这应用程序相同类型的功能:的 https://itunes.apple.com/us/app/fancy-units/id850306139?mt=8

I would like to implement the same type of functionality as this application: https://itunes.apple.com/us/app/fancy-units/id850306139?mt=8

当用户选择一个表格视图单元格,单元格动画填满整个屏幕,显示动画的同时一个新的观点。

When a user selects a table view cell, the cell animates to fill the entire screen and reveals a new view while animating.

我一直在试图找到如何做到这一点信息,但不能完全似乎找到任何好的资源。

I have been trying to find information on how to do this but can't quite seem to find any good resources.

我怎样才能做到这一点?甚至只是如何妥善谷歌搜索的想法将是非常有益的!

How can I accomplish this? Even just an idea of what to properly google search will be extremely helpful!

推荐答案

我不知道花式单位怎么做的,但我能够复制它们的外观与这个例子。初始视图控制器(TableController)是一个UIViewController子类与显示基本单元表视图。我有固定到其视图顶部的故事板另一个控制器,ViewController中,有一个单独的表视图单元格(而不是表视图中)(约束的侧面和顶部,和44的高度约束)。我添加此控制器作为一个孩子,并添加它的视图在顶部,你点击单元格,并给它的单元格的边框,背景颜色和文本的文本标签,然后将其动画全屏。我在ViewController中定义一个委托协议,当你点击单元格中的折叠按钮这就是所谓的。该协议的一个方法,expandedCellWillCollapse,在TableController实现到控制器动画回落。这里的code,

I don't know how Fancy Units does it, but I was able to replicate their look with this example. The initial view controller (TableController) is a UIViewController subclass with a table view that displays basic cells. I have another controller in the storyboard, ViewController that has a single table view cell (not inside a table view) pinned to the top of its view (constraints to the sides and top, and a height constraint of 44). I add this controller as a child, and add it's view over top the cell you click on, and give it the cell's frame, background color, and text in the text label, then animate it to the full screen. I have a delegate protocol defined in ViewController that's called when you click on the collapse button in the cell. The protocol's single method, expandedCellWillCollapse, is implemented in TableController to animate the controller back down. Here's the code,

#import "TableController.h"
#import "ViewController.h"

@interface TableController ()
@property (strong,nonatomic) NSArray *theData;
@property (weak,nonatomic) IBOutlet UITableView *tableView;
@property (strong,nonatomic) ViewController *expander;
@property (nonatomic) CGRect chosenCellFrame;
@end

@implementation TableController 


- (void)viewDidLoad {
    [super viewDidLoad];
    self.theData = @[@"One",@"Two",@"Three",@"Four",@"Five",@"Six",@"Seven",@"Eight",@"Nine",@"Black",@"Brown",@"Red",@"Orange",@"Yellow",@"Green",@"Blue"];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.theData.count;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.contentView.backgroundColor = [UIColor colorWithHue:.1 + .07*indexPath.row saturation:1 brightness:1 alpha:1];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.textLabel.text = self.theData[indexPath.row];
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (! self.expander) {
        self.expander = [self.storyboard instantiateViewControllerWithIdentifier:@"Expander"];
        self.expander.delegate = self;
    }
    [self addChildViewController:self.expander];
    self.expander.view.frame = [self.tableView rectForRowAtIndexPath:indexPath];
    self.expander.view.center = CGPointMake(self.expander.view.center.x, self.expander.view.center.y - self.tableView.contentOffset.y); // adjusts for the offset of the cell when you select it
    self.chosenCellFrame = self.expander.view.frame;
    self.expander.view.backgroundColor = [UIColor colorWithHue:.1 + .07*indexPath.row saturation:1 brightness:1 alpha:1];
    UILabel *label = (UILabel *)[self.expander.cell viewWithTag:1];
    label.text = self.theData[indexPath.row];
    [self.view addSubview:self.expander.view];
    [UIView animateWithDuration:.5 animations:^{
        self.expander.view.frame = self.tableView.frame;
        self.expander.collapseButton.alpha = 1;
    } completion:^(BOOL finished) {
        [self.expander didMoveToParentViewController:self];
    }];
}


-(void)expandedCellWillCollapse { // delegate method called from the collapse button in the expanded cell
    [self.expander willMoveToParentViewController:nil];
    [UIView animateWithDuration:.5 animations:^{
        self.expander.view.frame = self.chosenCellFrame;
        self.expander.collapseButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self.expander.view removeFromSuperview];
        [self.expander removeFromParentViewController];
    }];
}

这是不打算成为一个竞争的解决方案,但它应该让你开始。我在这里上传了该项目(编辑14年12月4日,使之适用于iOS 8工作),的http:// JMP。 SH / VKeIJLW

This isn't intended to be a compete solution, but it should get you started. I've uploaded this project here (edited 12/04/14 to make it work for iOS 8), http://jmp.sh/VKeIJLW .

这篇关于iOS版动画表视图单元为全屏幕横置时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆