iOSテーブルビューは、プルダウン画像の拡大効果を実現します。
ここの例では、iOSがドロップダウン画像の拡大効果を示す具体的なコードを共有しています。参考にしてください。具体的な内容は以下の通りです。
#import "ViewController.h"
#define kScreenbounds [UIScreen mainScreen].bounds
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
//
#define pictureHeight 200
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *pictureImageView;
@property (nonatomic, strong) UIView *header;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.title = @" ";
// translucent NO,
self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;
[self createTableView];
}
- (void)createTableView
{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
// ImageView
self.header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, pictureHeight)];
_pictureImageView = [[UIImageView alloc] initWithFrame:_header.bounds];
_pictureImageView.image = [UIImage imageNamed:@"picture"];
/*
*/
// UIViewContentModeScaleAspectFill UIView
_pictureImageView.contentMode = UIViewContentModeScaleAspectFill;
// YES , . _pictureImageView _header .
_pictureImageView.clipsToBounds = YES;
[_header addSubview:_pictureImageView];
self.tableView.tableHeaderView = _header;
[self.view addSubview:_tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.textLabel.text = @" ";
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
/**
* contentInset 0
*/
// tableView
CGFloat Offset_y = scrollView.contentOffset.y;
//
if ( Offset_y < 0) {
//
CGFloat totalOffset = pictureHeight - Offset_y;
//
CGFloat scale = totalOffset / pictureHeight;
CGFloat width = kScreenWidth;
//
_pictureImageView.frame = CGRectMake(-(width * scale - width) / 2, Offset_y, width * scale, totalOffset);
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。