iOS:将UIImageView翻转到UITableView

iOS:将UIImageView翻转到UITableView,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,正在制作自定义动画,该动画将执行以下操作: 从图像视图开始-->水平翻转为相同大小的表视图。它应该看起来像是图像后面的表视图 我试过这个: [UIView transitionFromView:imgView toView:tbl duration:1 options:UIViewAnimationOptionTransitionFlipFro

正在制作自定义动画,该动画将执行以下操作:

从图像视图开始-->水平翻转为相同大小的表视图。它应该看起来像是图像后面的表视图

我试过这个:

  [UIView transitionFromView:imgView      
                        toView:tbl
                      duration:1
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    completion:nil];
但这只是翻转了superview,这没有帮助。我是否需要以某种方式实现容器视图?这似乎有些过分(但可能是因为我不知道如何使用它们)

我是动画新手。

故事板:

确保在图像视图上启用了用户交互

接口:

//
//  ViewController.h
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@end

是的,你需要使用一个容器


我相信
transitionFromView:toView
做的事情与
transitionWithView
做的事情是一样的,对“to”和“from”子视图进行了一些额外的操作。文档中没有这样说。这只是我从实验中得出的结论。

您不需要容器视图。可以将视图控制器与UIImageView和UITableView的子视图一起使用。看我的答案;)阅读以下问题:)“这只是翻转superview,这没有帮助”是的,我使用了容器视图。这比我想象的要容易得多,只是一开始我不太明白。但这和我刚才的问题完全一样,容器是superview,我的错,Timothy。错过了有关superview的部分。
//
//  ViewController.m
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // This assumes a static table with 3 rows; update accordingly.
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MyCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier forIndexPath: indexPath];

    // Cell 1, Cell 2, Cell 3, etc.
    cell.textLabel.text = [NSString stringWithFormat: @"Cell %d", indexPath.row];

    return cell;
}

// Listen for touches and call "flipToTable" when the image view is tapped.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    if (touch.view == _imageView)
    {
        [self flipToTable];
    }
}

- (void)flipToTable
{
    [UIView transitionFromView: _imageView
                        toView: _tableView
                      duration: 1
                       options: UIViewAnimationOptionTransitionFlipFromLeft
                    completion: nil];
}

@end