iOS开发 上拉查看图片详情实现思路

原文链接:
来源: http://www.2cto.com/kf/201507/419749.html

基本思路:
1、设置一个 UIScrollView 作为视图底层,并且设置分页为两页
2、然后在第一个分页上添加一个 UITableView 并且设置表格能够上提加载(上拉操作即为让视图滚动到下一页)
3、 在第二个分页上添加一个 UIWebView 并且设置能有下拉刷新操作(下拉操作即为让视图滚动到上一页)

ps:以上所提及UITableView与UIWebView 可以自行更改为其他滚动控件也是可行的

实现需要的第三方支持:MJRefresh
关于此第三方,可参考:githua 地址 请点击此处

以下是具体代码实现:

定义宏:

?
1
2
<code class = "hljs" cs= "" >#define IPHONE_W ([UIScreen mainScreen].bounds.size.width)
#define IPHONE_H ([UIScreen mainScreen].bounds.size.height)</code>

@interface 部分

?
1
2
3
4
5
6
7
<code class = "hljs" objectivec= "" > @interface ViewController ()<uitableviewdatasource,uitableviewdelegate>
 
@property (strong,nonatomic)UIScrollView *scrollV;
@property (strong,nonatomic)UITableView *tableV;
@property (strong,nonatomic)UIWebView *webV;
 
@end </uitableviewdatasource,uitableviewdelegate></code>

@implementation 部分

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<code class = "hljs" objectivec= "" >- ( 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
</code>

 


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值