2013-09-01 41 views
0

希望做一个自定义动画,将做到以下几点:iOS版:翻转的UIImageView到的UITableView

开始时的图像视图 - >水平翻转成的tableview是相同的大小。它应该看起来像表格视图在图像的背面。

我已经试过这样:

[UIView transitionFromView:imgView  
         toView:tbl 
         duration:1 
         options:UIViewAnimationOptionTransitionFlipFromLeft 
        completion:nil]; 

但是,这只是翻转不利于上海华。我是否需要以某种方式实现容器视图?这似乎是矫枉过正(但可能是因为我不知道如何使用它们)。

我是新来的动画。

回答

0

是的,你需要使用的容器。

我相信transitionFromView:toView做了与transitionWithView一样的事情,并对“to”和“from”子视图进行了一些附加操作。文件没有说这个。这只是我的实验结论。

+0

您不需要容器视图。您可以为UIImageView和UITableView使用带有子视图的View Controller。看到我的回答;) – JWK

+0

阅读问题:)“这只是翻转超级无视帮助” –

+0

是的,我用了一个容器视图。这比我预想的要容易得多,起初我并不完全明白。但是,它与我刚才在问题中所使用的完全相同的解决方案是容器是超级视图。 – JoshDG

0

故事板:

请启用确保用户交互上的图像视图。

enter image description here

接口:

// 
// ViewController.h 
// 

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> 

@end 

实现:

// 
// 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