模仿淘宝上提加载图文详情的功能


基本思路:
1、设置一个 UIScrollView 作为视图底层,并且设置分页为两页
2、然后在第一个分页上添加一个 UITableView 并且设置表格能够上提加载(上拉操作即为让视图滚动到下一页)
3、 在第二个分页上添加一个 UIWebView 并且设置能有下拉刷新操作(下拉操作即为让视图滚动到上一页)
ps:以上所提及UITableView与UIWebView 可以自行更改为其他滚动控件也是可行的
实现需要的第三方支持:MJRefresh
关于此第三方,可参考:githua 地址 请点击此处
以下是具体代码实现:
定义宏:
#define IPHONE_W ([UIScreen mainScreen].bounds.size.width)#define IPHONE_H ([UIScreen mainScreen].bounds.size.height)
@interface 部分
@interface ViewController ()
@property(strong,nonatomic)UIScrollView *scrollV;
@property(strong,nonatomic)UITableView *tableV;
@property(strong,nonatomic)UIWebView *webV;
@end
@implementation 部分
- (void)viewDidLoad {  
[super viewDidLoad];  
//控件添加到视图上  
/** * 设置一个 UIScrollView 作为视图底层,并且设置分页为两页 * 然后在第一个分页上添加一个 UITableView 并且设置表格能够上提加载(上拉操作即为让视图滚动到下一页) 在第二个分页上添加一个 UIWebView 并且设置能有下拉刷新操作(下拉操作即为让视图滚动到上一页) */  
[self.view addSubview:self.scrollV];  
[self.scrollV addSubview:self.tableV];  
[self.scrollV addSubview:self.webV];  
//设置UITableView 上拉加载  
self.tableV.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ //上拉,执行对应的操作---改变底层滚动视图的滚动到对应位置 //设置动画效果  
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionLayoutSubviews animations:^{ self.scrollV.contentOffset = CGPointMake(0, IPHONE_H); } completion:^(BOOL finished) { 
//结束加载 [self.tableV.footer endRefreshing]; }];
}];  
//设置UIWebView 有下拉操作  
self.webV.scrollView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{  
//下拉执行对应的操作  
self.scrollV.contentOffset = CGPointMake(0, 0);  
//结束加载  
[self.webV.scrollView.header endRefreshing]; }];}
-(void)viewWillAppear:(BOOL)animated{ 
[self.webV loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@http://www.baidu.com]]];}
#pragma mark -- UITableView DataSource && Delegate
//返回表格分区行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{  
return 20;
}
//定制单元格内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{  
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];  
cell.textLabel.text = [NSString stringWithFormat:@%ld--%ld,indexPath.section,indexPath.row];  
return cell;
}
#pragma mark ---- get
- (UIScrollView *)scrollV{  
if (_scrollV == nil)  
{ _scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_W, IPHONE_H)];
_scrollV.contentSize = CGSizeMake(IPHONE_W, IPHONE_H * 2);  
//设置分页效果  
_scrollV.pagingEnabled = YES;  
//禁用滚动  
_scrollV.scrollEnabled = NO;  
} return _scrollV;}
-(UITableView *)tableV{  
if (_tableV == nil) {  
_tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_W, IPHONE_H) style:UITableViewStylePlain];  
_tableV.delegate = self;  
_tableV.dataSource = self;  
}
return _tableV;
}
-(UIWebView *)webV{  
if (_webV == nil)  
{  
_webV = [[UIWebView alloc]initWithFrame:CGRectMake(0, IPHONE_H, IPHONE_W, IPHONE_H)];  
}  
return _webV;
}
- (void)didReceiveMemoryWarning {  
[super didReceiveMemoryWarning];  
// Dispose of any resources that can be recreated.}@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值