故事板:
确保在图像视图上启用了用户交互。
界面:
//
// 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