首页 > 代码库 > 让UIScrollView、UITableView的滚动条一直显示
让UIScrollView、UITableView的滚动条一直显示
先用xcode5.1.1或更低版本创建一个Category,如图:
然后拷贝以下代码到刚创建的UIImageView+ForScrollView.m文件中:
- (void) setAlpha:(float)alpha { if (self.superview.tag == noDisableVerticalScrollTag) { if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin) { if (self.frame.size.width < 10 && self.frame.size.height > self.frame.size.width) { UIScrollView *sc = (UIScrollView*)self.superview; if (sc.frame.size.height < sc.contentSize.height) { return; } } } } if (self.superview.tag == noDisableHorizontalScrollTag) { if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleTopMargin) { if (self.frame.size.height < 10 && self.frame.size.height < self.frame.size.width) { UIScrollView *sc = (UIScrollView*)self.superview; if (sc.frame.size.width < sc.contentSize.width) { return; } } } } [super setAlpha:alpha];}
在.pch中定义这两个值:
#define noDisableVerticalScrollTag 836913#define noDisableHorizontalScrollTag 836914
然后在你所用到UIScrollView、UITableView的视图控制器中:
#import "UIImageView+ForScrollView.h"
设置UIScrollView、UITableView:
UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:self.view.bounds]; scrollview.contentSize = CGSizeMake(320, 960); scrollview.tag = noDisableVerticalScrollTag; [scrollview flashScrollIndicators]; [self.view addSubview:scrollview]; //--- _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 66, 320, 480)]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.showsHorizontalScrollIndicator = YES; _tableView.tag = noDisableVerticalScrollTag; [_tableView flashScrollIndicators]; [self.view addSubview:_tableView];
如此即可让UIScrollView、UITableView的滚动条一直显示。
让UIScrollView、UITableView的滚动条一直显示
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。