故事板:
请启用确保用户交互上的图像视图。
![enter image description here](https://i.stack.imgur.com/XhK9p.png)
接口:
//
// 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
来源
2013-09-01 02:05:23
JWK
您不需要容器视图。您可以为UIImageView和UITableView使用带有子视图的View Controller。看到我的回答;) – JWK
阅读问题:)“这只是翻转超级无视帮助” –
是的,我用了一个容器视图。这比我预想的要容易得多,起初我并不完全明白。但是,它与我刚才在问题中所使用的完全相同的解决方案是容器是超级视图。 – JoshDG