表格的下拉放大 ----------王朋

表格下拉放大的效果是:

创建TableView和ImageView,分别设置相关属性:

_tableView=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    //设置TableView的contentInset属性
     _tableView.contentInset=UIEdgeInsetsMake(imageHeight, 0, 0, 0);
    [self.view addSubview:_tableView];
    _imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, -imageHeight, self.view.frame.size.width,imageHeight )];
    _imageView.image=[UIImage imageNamed:@"icon.jpg"];
    //关键代码:UIViewContentModeScaleAspectFill,  contents scaled to fill with fixed aspect. some portion of content may be clipped.
    _imageView.contentMode=UIViewContentModeScaleAspectFill;

    [_tableView insertSubview:_imageView atIndex:0];

然后再在代理方法中改变图片的Frame

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat h=scrollView.contentOffset.y;
    if (-h > imageHeight) {
        CGRect frame=_imageView.frame;
        frame.size.height=-h;
        frame.origin.y=h;
        _imageView.frame=frame;
    }

    NSLog(@"偏移量是%f",h);
}
时间: 2024-08-25 15:56:11

表格的下拉放大 ----------王朋的相关文章

iOS开发-UITableView顶部图片下拉放大

关于顶部图片下拉放大,在用户展示的个人中心显示用户个人头像信息,设置UITableView的headerView实现,UITableView继承自UIScrollView,同样的设置UIScrollView的顶部图片也可以实现同样的效果,简单看一下实现的效果: 控制器中设置需要的属性变量: @property (strong,nonatomic) UITableView *tableView; @property (strong,nonatomic) NSArray *data; @proper

iOS 使用TableView实现下拉放大

第一步: 布置需要放大的TopView: 1. 创建TopView UIImageView *topView = [[UIImageView alloc] init]; 2. 设置图片 UIImage *image = [UIImage imageNamed:@"Big.jpg"]; topView.image = image; 3. 设置TopView的初始位置及内容模式 // 初始位置 topView.frame = CGRectMake(0, -TopViewH, ScreenW

动画特效十:下拉放大

今天继续我们的动画之行.这一次讲解的动画效果,在很多app中都能见到,就是下拉放大图片的效果.先看看效果图. 注:UITableView中内容的展示,不是本节的重点,所以忽略不计. 一.动画分析: 1. 默认情况下,图片正常显示(没有被拉大),并且导航条是隐藏的. 2. 当往下拉动的时候,图片等比例放大,并且选项卡(Tab1 和 Tab2)的View也会跟着下来. 3. 当往上推的时候,当选项卡推到导航栏正下方的时候,图片完全消失,导航栏也完全出现,并且不允许再往上推. 二.方案设计: 1. 头

iOS UI开发--下拉放大

1. 要实现的效果,左图为下拉前,右图为下拉后   2.首先最容易想到的是往tableHeaderView上,放一张图片. 但是tableHeaderView的宽度是固定的,这就意味着不容易做缩放效果; 顶部的上边界始终和tableView的上边界挨着,这就意味着下拉前只显示部分图片的效果,不容易实现. 3.最终方案:给tableView添加一张图片作为子视图, 并且图片应该在cell的下面,一开始图片只显示一部分 4. 示例代码 4.1 在ViewDidload方法中: UIImage *a

猫猫学iOS之tableView的下拉放大图片的方法

猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243 一:效果 tableview下拉的时候上部分图片放大会 二:代码 直接上代码,自己研究吧 #import "NYViewController.h" //图片的高度 const CGFloat NYTopViewH = 350; @interface NYViewController () @property (nonatomic, weak) UIIm

Android 仿美团网,大众点评购买框悬浮效果,仿美团详情页,可下拉放大图片,向上滚动图片,松手有动画

直接上代码注释都写到代码里面了: 自定义的ScrollView package mm.shandong.com.testmtxqcomplex.myui; import android.content.Context; import android.util.AttributeSet; import android.widget.ScrollView; /**  * Created by buyadong on 2016/7/29.  */ public class MyScrollView e

新闻详情页顶部的下拉放大与上拉的层叠效果

条件一:  [self.view insertSubview:_imgView belowSubview:_tableView]; 条件二: static NSString *cellId = @"cell1"; cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellSty

表的头视图下拉放大效果

ViewController.h @interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> { UIImageView *_imageView; } ViewController.m <p>#import "ViewController.h"</p> @interface ViewController () @end @impleme

图片下拉放大

// ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UITableViewController @end // ViewController.m #import "ViewController.h" const CGFloat HMTopViewH = 350; // 设置图片高度 @interface ViewController () @property (nonatomic,